日期:2014-05-20 浏览次数:20938 次
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager
.getConnection("jdbc:mysql://localhost/zhonghongfa?"
+ "user=root&password=841017");
conn.setAutoCommit(false);
pstmt = conn.createStatement();
pstmt.addBatch("insert into ddltable(id,name) values(301,'zhang')");
pstmt.addBatch("insert into ddltable(id,name) values(302,'zhsdfg')");
pstmt.executeBatch();
conn.rollback();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
try {
if(conn!=null)
{
conn.rollback();
conn.setAutoCommit(true);
}
} catch (SQLException e) {
e.printStackTrace();
}
}