?? usereo.java
字號:
package book.chat.table;
import java.sql.ResultSet;
import java.sql.SQLException;
import book.chat.DbManager;
public class UserEO {
protected int userID;// 代表數據庫中user_id列
protected String userName;// 代表數據庫中user_name列
protected String startTime;// 代表數據庫中start_time列
public UserEO() {// 無參的構造方法
this.userID = -1;
}
public UserEO(int id) {// 有參的構造方法,參數為user_id
this.userID = id;
if (!FromDb())// 如果有找到該id的user
this.userID = -1;
}
public boolean FromDb() {// 從數據庫中讀出,并更新bean
int row = -1;
// 讀記錄的sql語句
String sql = "select * from user where user_id=" + this.userID;
ResultSet rs = DbManager.getResultSet(sql);// 執行sql語句并返回ResultSet
try {
rs.last();// 移動到最后一行
row = rs.getRow();// 得到總記錄數
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 {// 最后關閉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;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -