sharding-jdbc-raw-jdbc-java-example getMetaData() 再 setAutoCommit(false) 无法对之后创建的 realconnection 生效 #472
Closed
Description
Sharding-jdbc 2.0.0.M3
example master 分支
为复现此情况,修改 sharding-jdbc-raw-jdbc-java-example 中的 RawJdbcRepository 的 execute() 方法:
Connection conn = dataSource.getConnection();
conn.getMetaData();
conn.setAutoCommit(false);
Statement statement = conn.createStatement();
statement.execute(sql);
conn.commit();
statement.close();
conn.close();
getMetaData() 时获取了一个 realconnection 存入了 AbstractConnectionAdapter 的 cachedConnections 中,导致之后的
cachedConnections 中一个连接是 autocommit = true 另一个 autocommit = false 在 commit 时,报错了:
Exception in thread "main" java.sql.SQLException
at io.shardingjdbc.core.jdbc.adapter.WrapperAdapter.throwSQLExceptionIfNecessary(WrapperAdapter.java:82)
at io.shardingjdbc.core.jdbc.adapter.AbstractConnectionAdapter.commit(AbstractConnectionAdapter.java:77)
at io.shardingjdbc.example.jdbc.java.repository.RawJdbcRepository.execute(RawJdbcRepository.java:109)
at io.shardingjdbc.example.jdbc.java.repository.RawJdbcRepository.createTable(RawJdbcRepository.java:33)
at io.shardingjdbc.example.jdbc.java.repository.RawJdbcRepository.demo(RawJdbcRepository.java:21)
at io.shardingjdbc.example.jdbc.java.RawJdbcJavaShardingDatabaseAndTableMain.main(RawJdbcJavaShardingDatabaseAndTableMain.java:40)