?? teldao.java
字號:
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class TelDAO {
Statement stmt;
public TelDAO() throws SQLException{
this.stmt=CreateConnection.conn.createStatement();
}
public boolean insert(String name,String tel) throws SQLException{
String sql="insert into tel values('"+name+"','"+tel+"')";
int info=this.stmt.executeUpdate(sql);
if(info>0){
return true;
}else{
return false;
}
}
public boolean update(int index,String name,String tel) throws SQLException{
String sql="update tel set name='"+name+"',tel='"+tel+"' where id="+index;
int info=this.stmt.executeUpdate(sql);
return info>0;
}
public boolean delete(int id) throws SQLException{
String sql="delete from tel where id='"+id+"'";
int info=this.stmt.executeUpdate(sql);
return info>0;
}
public List findByName(String name) throws SQLException{
String sql="select * from tel where name='"+name+"'";
ResultSet rs=this.stmt.executeQuery(sql);
List telList=new ArrayList();
while(rs.next()){
TelBean telBean=new TelBean();
telBean.setName(rs.getString("name"));
telBean.setTel(rs.getString("tel"));
telBean.setId(rs.getInt("id"));
telList.add(telBean);
}
return telList;
}
public List findAll() throws SQLException{
String sql="select * from tel order by name";
ResultSet rs=this.stmt.executeQuery(sql);
List telList=new ArrayList();
while(rs.next()){
TelBean telBean=new TelBean();
telBean.setName(rs.getString("name"));
telBean.setTel(rs.getString("tel"));
telBean.setId(rs.getInt("id"));
telList.add(telBean);
}
return telList;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -