1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| public class UserDaoImpl { public User getUserInfo(String uname,String upwd) throws ClassNotFoundException, SQLException{ User u=null; Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "oracle"); String sql="select * from t_user where uname=? and upwd=?"; PreparedStatement ps=conn.prepareStatement(sql); ps.setString(1, uname); ps.setString(2, upwd); ResultSet rs=ps.executeQuery(); while(rs.next()){ u=new User(); u.setUnum(rs.getInt("unum")); u.setUname(rs.getString("uname")); u.setUpwd(rs.getString("upwd")); return u; } rs.close(); ps.close(); conn.close(); return u; } public int insUser2() throws ClassNotFoundException, SQLException{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "oracle"); String sql="insert into t_user values(?,?,?)"; PreparedStatement ps=conn.prepareStatement(sql); ps.setInt(1, 7); ps.setString(2,"赵六"); ps.setString(3,"666"); int i=ps.executeUpdate(); ps.close(); conn.close(); return i; } public int upUser(String uname,int unum) throws ClassNotFoundException, SQLException{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "oracle"); String sql="update t_user set uname=? where unum=?"; PreparedStatement ps=conn.prepareStatement(sql); ps.setString(1, uname); ps.setInt(2, unum); int i=ps.executeUpdate(); ps.close(); conn.close(); return i; } public int delUser(int unum) throws ClassNotFoundException, SQLException{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "oracle"); String sql="delete from t_user where unum=?"; PreparedStatement ps=conn.prepareStatement(sql); ps.setObject(1, unum); int i=ps.executeUpdate(); ps.close(); conn.close(); return i; } }
|