用jsp+servlet+javaBean做的一个简单通讯录

  • V1_145974
    了解作者
  • 1.5MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 00:13
    上传日期
用jsp+servlet+javaBean做的一个简单通讯录,实现了一些简单的功能,希望可以为学习jsp的朋友带来帮助。
BookTest.rar
内容介绍
package operation; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import conbean.ConnDBean; import entity.BookBean; import entity.UsersBean; public class BookBeanB { private Connection con; private Statement stm;//用于执行SQL语句 private PreparedStatement ps;//用于执行SQL语句(预处理) private ResultSet rs;//用于保存查询的结果集 public List ArraylistBook(String guanxi){ List list=new ArrayList(); BookBean book=null; String sql="select * from book where guanxi=?"; try { con=ConnDBean.getCon(); ps=con.prepareStatement(sql); ps.setString(1, guanxi); rs=ps.executeQuery(); while(rs.next()){ book=new BookBean(); book.setId(rs.getInt("id")); book.setBookname(rs.getString("bookname")); book.setPhone(rs.getString("phone")); book.setSex(rs.getString("sex")); book.setAddress(rs.getString("address")); book.setGuanxi(rs.getString("guanxi")); list.add(book); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { if(rs!=null) rs.close(); if(ps!=null)ps.close(); if(con!=null)con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return list; } public int insertbook(String bookname,String phone,String sex,String address,String guanxi){ int count=0; con=ConnDBean.getCon(); String sql1="select bookname from book where bookname=?"; String sql="insert into book(bookname,phone,sex,address,guanxi) values(?,?,?,?,?)"; try { ps=con.prepareStatement(sql1); ps.setString(1,bookname); rs=ps.executeQuery(); if(rs.next()){ count=0; System.out.print("添加失败,该用户名以存在"); }else{ ps=con.prepareStatement(sql); ps.setString(1,bookname); ps.setString(2,phone); ps.setString(3,sex); ps.setString(4,address); ps.setString(5,guanxi); count=ps.executeUpdate(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { if(rs!=null)rs.close(); if(ps!=null)ps.close(); if(con!=null)con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return count; } public int delectbook(int id){ int count=0; String sql="delete from book where id=?"; con=ConnDBean.getCon(); try { ps=con.prepareStatement(sql); ps.setInt(1, id); count=ps.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(ps!=null)ps.close(); if(con!=null)con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return count; } public List ArraylistBooka(){ List list=new ArrayList(); BookBean book=null; String sql="select * from book"; try { con=ConnDBean.getCon(); ps=con.prepareStatement(sql); rs=ps.executeQuery(); while(rs.next()){ book = new BookBean(); book.setId(rs.getInt("id")); book.setBookname(rs.getString("bookname")); book.setPhone(rs.getString("phone")); book.setSex(rs.getString("sex")); book.setAddress(rs.getString("address")); book.setGuanxi(rs.getString("guanxi")); list.add(book); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { if(rs!=null) rs.close(); if(ps!=null)ps.close(); if(con!=null)con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return list; } public int updateBook(String phone,String address,String guanxi,int id){ int count=0; String sql="update book set phone=?,address=?,guanxi=? where id=? "; con=ConnDBean.getCon(); try { ps=con.prepareStatement(sql); ps.setString(1,phone); ps.setString(2, address); ps.setString(3,guanxi); ps.setInt(4,id); count=ps.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { if(ps!=null)ps.close(); if(con!=null)con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return count; } }
评论
    相关推荐
    • Java
      Java
    • java
      Java
    • Java
      Java
    • Java
      Java项目
    • Java
      Java 对于Java练习
    • java
      Java 此回购包括我学习Java的旅程。
    • java
      Java Java基础
    • Java
      Java
    • Java
      Java 我创建的Java项目
    • Java
      Java 2021/02/19 .java Main.java 学生.java Bmi.java 。班级 Bmi类 主类 MyBmi.class 学生班 学生样本类 2021/02/20 .java DeleteFile.java WriteFile.java MyDataPrint.java 。班级 DeleteFile.class ...