private Connection connection;
private Statement pre;
public String set(String goal,String marriage){
return "update info set goal='"+goal+"'where marriage='"+marriage+"'";
}
public void start(){
String sql="jdbc:mysql://127.0.0.1/student";
try {
connection = DriverManager.getConnection(sql,"root","111");
connection.setAutoCommit(false);
pre = connection.createStatement();
pre.executeUpdate(set("配偶","未婚"));
pre.executeUpdate(set("情人","已婚"));
pre.executeUpdate(set("包养","学生"));
if(true)
throw new SQLException("ni");
connection.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
connection.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}