📄 dbscheme.java~
字号:
/**
* Copyright (c) 2002 CODEFAD.com
* All right reserved.
*
* Description: ....
*
* Author: Chu Daping 2002-5-21 10:39
*
*/
package com.codefad.easyoffice.db;
import java.sql.*;
import java.util.*;
import java.io.*;
import com.codefad.easyoffice.*;
public final class DbScheme implements Scheme {
private static final String LOAD_SCHEME_BY_ID =
"SELECT * FROM jihua WHERE schemeID=?";
private static final String LOAD_SCHEME_BY_OBJDATE =
"SELECT * FROM jihua WHERE objdate=?";
private static final String INSERT_SCHEME =
"INSERT INTO jihua(deptID, stationID, userID, subject, content ," +
"createdate, objdate) VALUES(?,?,?,?,?,?,?)";
private static final String SAVE_SCHEME =
"UPDATE jiahua SET userID=?, subject=?, content=?, objdate=?, createdate=? WHERE schemeID=?";
private static final String DELETE_SCHEME =
"DELETE FROM jihua WHERE schemeID=?";
private long schemeID = -1;
private java.util.Date createdate = null;
private String subject = null;
private String body = null;
private String objdate = null;
private long userID = -1;
protected long deptID = -1;
protected long stationID = -1;
private boolean isReadyToSave = false;
public DbScheme(long stationID,long deptID,long userID,String subject,
String content,String objdate)
{
this.stationID = stationID;
this.deptID = deptID;
this.userID = userID;
this.subject= subject;
this.body = content;
this.objdate= objdate;
InsertToDb();
}
public DbScheme(long id)
{
this.schemeID = id;
loadFromDbById();
isReadyToSave = true;
}
public DbScheme(String objdate)
{
this.objdate = objdate;
loadFromDbByObjdate();
isReadyToSave = true;
}
private void loadFromDbById()
{
try {
Connection con = new SqlCon().getConnection();
PreparedStatement pstmt = con.prepareStatement(LOAD_SCHEME_BY_ID);
pstmt.setLong(1, schemeID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
deptID = rs.getLong("deptID");
stationID = rs.getLong("stationID");
userID = rs.getLong("userID");
subject = rs.getString("subject");
body = rs.getString("content");
createdate = rs.getDate("createdate");
objdate = rs.getString("objdate");
}
rs.close();
pstmt.close();
con.close();
}
catch( SQLException sqle ) {
System.out.print(sqle.toString());
}
}
private void loadFromDbByObjdate()
{
try {
Connection con = new SqlCon().getConnection();
PreparedStatement pstmt = con.prepareStatement(LOAD_SCHEME_BY_OBJDATE);
pstmt.setString(1, objdate);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
schemeID = rs.getLong("schemeID");
deptID = rs.getLong("deptID");
stationID = rs.getLong("stationID");
userID = rs.getLong("userID");
subject = rs.getString("subject");
body = rs.getString("content");
createdate = rs.getDate("createdate");
}
rs.close();
pstmt.close();
con.close();
}
catch( SQLException sqle ) {
System.out.print(sqle.toString());
}
}
public long getID() {
return schemeID;
}
public String getObjDate() {
return objdate;
}
public void setObjDate(String objdate)
{
this.objdate = objdate;
saveToDb();
}
public java.util.Date getCreateDate() {
return createdate;
}
public void setCreateDate(java.util.Date createdate)
{
this.createdate = createdate;
saveToDb();
}
public String getSubject()
{
return subject;
}
public void setSubject(String subject)
{
this.subject = subject;
saveToDb();
}
public String getBody() {
return body;
}
public long getDeptID() {
return deptID;
}
public long getUserID() {
return userID;
}
public Department getDept() {
Department dept = new DbDepartment(deptID);
return dept;
}
public void setBody(String body)
{
this.body = body;
saveToDb();
}
public User getUser() {
User user = new DbUser(userID);
return user;
}
public void InsertToDb()
{
Connection con = new SqlCon().getConnection();
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(INSERT_SCHEME);
pstmt.setLong(1, deptID);
pstmt.setLong(2, stationID);
pstmt.setLong(3, userID);
pstmt.setString(4, subject);
pstmt.setString(5, body);
pstmt.setString(6, new Timestamp((new java.util.Date()).getTime()).toString());
pstmt.setString(7, objdate);
pstmt.executeUpdate();
} catch (Exception e) {
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
private synchronized void saveToDb(Connection con) throws SQLException
{
}
private synchronized void saveToDb() {
boolean abortTransaction = false;
Connection con = new SqlCon().getConnection();
try {
saveToDb(con);
}
catch( Exception e ) {
e.printStackTrace();
abortTransaction = true;
}
finally {
try { con.close(); }
catch (Exception e) { }
}
}
public void deleteScheme() {
deleteFromDb();
}
private synchronized void deleteFromDb() {
try {
Connection con = new SqlCon().getConnection();
PreparedStatement pstmt = con.prepareStatement(DELETE_SCHEME);
pstmt.setLong(1, schemeID);
pstmt.executeUpdate();
pstmt.close();
con.close();
} catch (Exception e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -