?? chateo.java
字號:
package book.chat.table;
import java.sql.ResultSet;
import java.sql.SQLException;
import book.chat.DbManager;
public class ChatEO {
protected int chatID;// 代表數據庫中chat_id列
protected String chatName;// 代表數據庫中chat_name列
protected String startTime;// 代表數據庫中start_time列
public ChatEO() {// 無參的構造方法
this.chatID = -1;
}
public ChatEO(int id) {// 有參的構造方法,參數為chat_id
this.chatID = id;
if (!FromDb())// 如果有找到該id的chat
this.chatID = -1;
}
public boolean FromDb() {// 從數據庫中讀出,并更新bean
int row = -1;
// 讀記錄的sql語句
String sql = "select * from chat where chat_id=" + this.chatID;
ResultSet rs = DbManager.getResultSet(sql);// 執行sql語句并返回ResultSet
try {
rs.last();// 移動到最后一行
row = rs.getRow();// 得到總記錄數
if (row == 1) {// 如果只查詢到一條記錄,則代表該記錄存在并更新該類的屬性
this.chatID = rs.getInt("CHAT_ID");
this.chatName = rs.getString("CHAT_NAME");
this.startTime = rs.getString("START_TIME");
return true;
} else
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {// 最后關閉ResutltSet,Statement.并釋放連接
if (rs != null)
rs.close();
if (rs.getStatement() != null)
rs.getStatement().close();
DbManager.releaseConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public int getChatID() {
return chatID;
}
public void setChatID(int chatID) {
this.chatID = chatID;
}
public String getChatName() {
return chatName;
}
public void setChatName(String chatName) {
this.chatName = chatName;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -