``public class Test01 {
public static void main(String[] args) {
ResultSet rs = null;
try {
rs = DBUitl.query("select * from t_user t");
while(rs.next()){
System.out.println(rs.getLong(1) + " "
+ rs.getString(2) +" "
+ rs.getDate(4));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBUitl.close(rs);
}
}
}
public class Test02 {
public static void main(String[] args) {
String url ="jdbc:mysql://localhost:3306/db1726";
Connection conn = null;
Statement sm = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,"u1726","u1726");
conn.setAutoCommit(false);
sm = conn.createStatement();
String sql1 = "update t_class set name = '班级名称1' where id = 11";
String sql2 = "delete from t_class where id = 11";
int i = sm.executeUpdate(sql1);
Savepoint sp1 = conn.setSavepoint();
i = sm.executeUpdate(sql2);
conn.rollback(sp1);
conn.commit();
System.out.println("更新的行数:" + i);
} catch (Exception e) {
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}finally{
try {
sm.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}