📄 mydao.java
字号:
package Dao;
import java.sql.*;
import java.util.*;
import Bean.*;
import ConnectionManager.*;
public class mydao {
public mydao() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private Connection conn = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
public Vector getAllDatas(){
Vector datas = new Vector();
try{
conn = ConnectionManagerMyAddrBook.getCon();
String sql = "select * from MyAddrBook";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
MyAddrBookBean bean = new MyAddrBookBean();
bean.setID(rs.getInt(1));
bean.setFirstName(rs.getString(2));
bean.setLastName(rs.getString(3));
bean.setJobTitle(rs.getString(4));
bean.setDepartMent(rs.getString(5));
bean.setOffPh(rs.getString(6));
bean.setMobile(rs.getString(7));
bean.setEmail(rs.getString(8));
datas.add(bean);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
closeAll();
}
return datas;
}
public int delUser(int uid){
int res = 0;
try{
conn = ConnectionManagerMyAddrBook.getCon();
String sql = "delete from MyAddrBook where ID=?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1,uid);
res = pstmt.executeUpdate();
}catch(Exception ex){
ex.printStackTrace();
}finally{
closeAll();
}
return res;
}
public void closeAll(){
try{
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -