学生管理系统,主要功能,增删改查 //添加学生
public int add(xuesheng s)
{
int ret=0;
//1.得到连接对象
con=shuju.lianjie();
if(con!=null)
{
try {
//2.得到语句对象
ps=con.prepareStatement("insert into stuInfo(sno,name,sex,birthday,phone,address) values(?,?,?,?,?,?)"); //参数化化查询
ps.setString(1, s.getId());
ps.setString(2, s.getName());
ps.setString(3, s.getSex());
ps.setString(4, s.getBirthday());
ps.setString(5, s.getPhone());
ps.setString(6, s.getAddress());
//3.执行查询
ret=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
//4.关闭
shuju.guanbi(rs, ps, con);
return ret;
}
//修改
public int xiugaixuesheng(xuesheng s)
{
int ret=0;
//1.得到连接对象
con=shuju.lianjie();
if(con!=null)
{
try {
//2.得到语句对象
ps=con.prepareStatement("update stuInfo set name=?,sex=?,birthday=?,phone=?,address=? where sno=?"); //参数化化查询
ps.setString(6, s.getId());
ps.setString(1, s.getName());
ps.setString(2, s.getSex());
ps.setString(3, s.getBirthday());
ps.setString(4, s.getPhone());
ps.setString(5, s.getAddress());
//3.执行查询
ret=ps.executeUpdate();
//4.关闭
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
shuju.guanbi(rs, ps, con);
return ret;
}
//删除
public int shanchu(String id)
{
int ret=0;
con=shuju.lianjie();
if(con!=null)
{
try {
ps=con.prepareStatement("delete stuInfo where sno=?");
ps.setString(1, id);
ret=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
shuju.guanbi(rs, ps, con);
return ret;
}
//查询
public ArrayList<xuesheng> chaxun()
{
ArrayList<xuesheng> al=new ArrayList<xuesheng>();
con=shuju.lianjie();
if(con!=null)
{
try {
PreparedStatement ps=con.prepareStatement("select* from stuInfo");
rs=ps.executeQuery();
while(rs.next())
{
xuesheng s=new xuesheng(rs.getString("sno"),rs.getString("name"),rs.getString("sex"),rs.getString("birthday"),rs.getString("phone"),rs.getString("address"), null);
al.add(s);
}
}
catch(Exception e)
{
//e.printStackTrace();
}
}
return al;
}
评论