Servlet实现增删改查功能代码实例

所需积分/C币:14 2015-12-08 21:10:55 367KB PDF

文件是PDF的格式,内容是使用Servlet实现增删改查功能代码和实例。
public int getIdO i return id public void setId (int id)[ thisid=id; public String getName0 t return name tblic void setName(String name) this, name name public String getPasswordO i return passwor public void setPassword(String password)[ S password= passwor public String getSex0 t return sex; public void setSex(String sex) this, sex =sex: public int getAgeOi return age; public void staGe(int age)( thisage= ages 2封裝数据库连接以及操作 JavaBean所用到的法,即DAO package muta, bean; import java. sql Connection; import java. sql Driver Manager; import java. sql PreparedStatements import java. sql ResultSet; import java. sql SQLException import iava. util. Arraylist import java. util. List; @author help *操作数据库的方法 public class SqlBean Connection con; PreparedStatement pre ResultSet rs; public SqlBeano Class for Name" com mysql jdbc Driver") I catch(Class Not Found Exception e)t e.printStackTraceO con=DriverManager,get Connection(jdbc: mysql: //127.0.0.1: 3306/M sErvlet",root,122828 ); I catch(SQLException e)i eprintStackTrace(; *(author help *插入新的一条记录 @return public int getInsert(String sql, Java Bean jBean) int count =O pre= con. prepare Statement(sql); Pre setString(1,j Bean. getNameO); presetString(2,] Bean. getPasswordo) resetString(3, jEan. getSexO) presetInt(4,jEan.getAgeO) count=pre executeUpdate(; I catch(SQLException e)t eprint Stack race; finally try I pre close; con. close; I catch(SQLException e)i l/ TODO Auto-generated catch block e.printStackTraceO; return count @author help *删除一条记录 Return public int get Delete(String sql, int id) int count =Oa pre =con.prepareStatement(sql); presetInt(1, id); count=pre executeUpdate O; 3 catch(SQLException e)i e.printStackT race; Nally pre.close con. Close; J catch(SQLException e)t // TODO Auto-generated catch block e printStackTrace O; return count *(author help *根据ID查询某一条记录 @return public JavaBean get Search Byld( String squint id) Java bean jEan new JavaBean Os pre=con.prepare Statement(sql); pre setInt(1, id rs=pre execute Query while(rs nextO) jEan setId(rs getInt(id")); iBean. setName(rsgetString("name")); iBean. setPassword(rsgetString ("password") jBean. setSex(rsgetString("sex") jBean. setAge(rs getInt(age")); 3 catch(SQLException e e. printStackTrace0; return ]Bean; /x @author help 本更新某一条记录 return public int get Update(String sql, Java Bean jEan) int count=0; pre con preparestatement(sql); pre setInt(5,jEan,getId o); presetString(1,jBean. getNameo) pre setString(2,j Bean. getPasswordo)

...展开详情
img
小尘鸟_
  • GitHub

    绑定GitHub第三方账户获取
  • 脉脉勋章

    绑定脉脉第三方账户获得

关注 私信 TA的资源

上传资源赚积分,得勋章
    最新推荐