public class Demo007 {
public static void main(String[] args) {
Connection conn=null;
PreparedStatement pst=null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql:///db1","root","root");
conn.setAutoCommit(false);
String sql="update emp set salary=8600 where id=3";
pst=conn.prepareStatement(sql);
int a= pst.executeUpdate();
System.out.println(a);
conn.commit();
} catch (Exception e) {
try {
if(conn!=null){
conn.rollback();}
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}finally{
JdbcUtil.colse(conn,pst,null);
}
}
} |
|