/*String tableName=””; String SQL =”select * from “+tableName; Conn = jdbcmysQL.getConnection (); conn = jdbcmysqL.getConnection (); PreparedStatement stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery(sql); While (rs.next()){// Query all rs.getString(“name”); } rs.close(); * /
/*String SQL =”insert into idandPassword (stuid,password) values(? ,?) “; Conn = jdbcmysQL.getConnection (); conn = jdbcmysqL.getConnection (); conn = conn; PreparedStatement stmt = conn.prepareStatement(sql); stmt.setString(1, “iddd”); Stmt.setstring (2, “123”); stmt.setString(2, “123”); // Insert the message stmt.executeUpdate(); stmt.close(); * /
/ / query /
String SQL =”update idandPassword set password =? , test = ? where stuid = ?” ; Conn = jdbcmysQL.getConnection (); conn = jdbcmysqL.getConnection (); PreparedStatement stmt = conn.prepareStatement(sql); stmt.setString(1,”aaaaa”); // stmt.setint (2, 122); stmt.setString(3,”zzz”); stmt.executeUpdate(); stmt.close(); * /
String SQL =”delete from idandPassword where stuid=?” ; PreparedStatement stmt = conn.prepareStatement(sql); stmt.setString(1,”ddd” ); // Delete data stmt.executeupdate () with id=” DDD “; stmt.close(); * /
On closing database connections: it is best to write a method in the utility class to close conn, STMT, and RS. JdbcMysql.closeAll(conn, stmt, rs);