STRUTS——SQL添加删除

  • Z2_766688
    了解作者
  • 1.4MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-25 05:49
    上传日期
STRUTS——SQL添加删除
SQL添加删除.rar
内容介绍
package net.Model; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import net.Conn.Conn; import net.View.UserVo; public class UserModel { Conn con; public void insert(UserVo Vo) {// 用户添加 con = new Conn(); PreparedStatement ps = null; System.out.println(Vo.getUsername()); System.out.println(Vo.getPassword()); System.out.println(Vo.getYzm()); String sql = "insert into inserUser values(?,?,?)"; try { ps = con.getcon().prepareStatement(sql); ps.setString(1, Vo.getUsername()); ps.setString(2, Vo.getPassword()); ps.setString(3, Vo.getYzm()); ps.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public ArrayList selectUser() {// 用户查询 con = new Conn(); ArrayList list = new ArrayList(); Statement stm = null; ResultSet rs = null; UserVo vo = null; String sql = "select * from inserUser"; try { stm = con.getcon().createStatement(); rs = stm.executeQuery(sql); while (rs.next()) { vo = new UserVo(); vo.setUserid(rs.getInt(1)); vo.setUsername(rs.getString(2)); vo.setPassword(rs.getString(3)); vo.setYzm(rs.getString(4)); list.add(vo); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } public void deletUser(int id) {// 用户删除 con = new Conn(); String sql = "delete from inserUser where userid=" + id; Statement stmt = null; try { stmt = con.getcon().createStatement(); stmt.executeUpdate(sql); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
评论
    相关推荐