mysql jdbc 执行 卡住_JDBC运行问题

public class JDBCtest {

public static void main(String[] args) {

Connection connection1=null;

Connection connection2=null;

PreparedStatement prepareStatement=null;

try {

Class.forName("com.mysql.jdbc.Driver");

connection1 = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/demo","root","zr129114");

connection2 = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/demo","root","zr129114");

connection2.setAutoCommit(false);

connection1.setAutoCommit(false);

prepareStatement = connection1.prepareStatement("update lala set result=result-1000 where id=1");

prepareStatement.executeUpdate();

// connection1.commit();

prepareStatement = connection2.prepareStatement("update lala set result=result-1000 where id=1");

prepareStatement.executeUpdate();

connection1.commit();

if(1>0) {

throw new SQLException();

}

prepareStatement = connection2.prepareStatement("update lala set result=result+1000 where id=2");

prepareStatement.executeUpdate();

connection2.commit();

} catch (ClassNotFoundException e) {

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

// try {

// connection2.rollback();

// } catch (SQLException e1) {

// e1.printStackTrace();

// }

}

finally {

if(null!=connection1)

try {

connection1.close();

} catch (SQLException e) {

e.printStackTrace();

}

if(null!=connection2)

try {

connection2.close();

} catch (SQLException e) {

e.printStackTrace();

}

if(null!=prepareStatement)

try {

prepareStatement.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

}

}

哪位大牛知道这段代码为什么会卡住?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值