?? usereo.java
字號(hào):
package book.chat.table;
import java.sql.ResultSet;
import java.sql.SQLException;
import book.chat.DbManager;
public class UserEO {
protected int userID;// 代表數(shù)據(jù)庫(kù)中user_id列
protected String userName;// 代表數(shù)據(jù)庫(kù)中user_name列
protected String startTime;// 代表數(shù)據(jù)庫(kù)中start_time列
public UserEO() {// 無(wú)參的構(gòu)造方法
this.userID = -1;
}
public UserEO(int id) {// 有參的構(gòu)造方法,參數(shù)為user_id
this.userID = id;
if (!FromDb())// 如果有找到該id的user
this.userID = -1;
}
public boolean FromDb() {// 從數(shù)據(jù)庫(kù)中讀出,并更新bean
int row = -1;
// 讀記錄的sql語(yǔ)句
String sql = "select * from user where user_id=" + this.userID;
ResultSet rs = DbManager.getResultSet(sql);// 執(zhí)行sql語(yǔ)句并返回ResultSet
try {
rs.last();// 移動(dòng)到最后一行
row = rs.getRow();// 得到總記錄數(shù)
if (row == 1) {// 如果只查詢到一條記錄,則代表該記錄存在并更新該類的屬性
this.userID = rs.getInt("USER_ID");
this.userName = rs.getString("USER_NAME");
this.startTime = rs.getString("START_TIME");
return true;
} else
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {// 最后關(guān)閉ResutltSet,Statement.并釋放連接
if (rs != null)
rs.close();
if (rs.getStatement() != null)
rs.getStatement().close();
DbManager.releaseConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -