通过 JDBC-ODBC 桥使用保存点:UnsupportedOperationException
Posted
技术标签:
【中文标题】通过 JDBC-ODBC 桥使用保存点:UnsupportedOperationException【英文标题】:Using savepoints with the JDBC-ODBC Bridge: UnsupportedOperationException 【发布时间】:2014-11-10 06:16:52 【问题描述】:我已将 NetBeans IDE 与 MS Access 连接,并且在执行事务时出现此错误。 似乎不支持保存点...请指导我..
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:cse");
Statement stmt1, stmt2, stmt3;
System.out.println("Statements created");
conn.setAutoCommit(false);
String query1 = " update registration set id='105' " +
"where first = 'Sumit' ";
String query2 = " update registration set id='106' " +
"where first = 'Zayed' ";
System.out.println(" Queries created");
stmt1 = conn.createStatement();
System.out.println(" Connection created");
Savepoint s1 = conn.setSavepoint("sp1");
System.out.println(" Savept created");
stmt2 = conn.createStatement();
stmt1.executeUpdate(query1);
stmt2.executeUpdate(query2);
conn.commit();
stmt3 = conn.createStatement();
stmt1.close();
stmt2.close();
conn.releaseSavepoint(s1);
conn.close();
错误是 创建的语句 创建的查询 已创建连接 错误:java.lang.UnsupportedOperationException
【问题讨论】:
【参考方案1】:JDBC-ODBC 桥显然根本不支持保存点。但是,UCanAccess JDBC 驱动程序确实支持未命名的保存点:
String connStr = "jdbc:ucanaccess://C:/__tmp/test.mdb";
try (Connection conn = DriverManager.getConnection(connStr))
conn.setAutoCommit(false);
try (Statement s = conn.createStatement())
s.executeUpdate("UPDATE ucaTest SET Field2='NEWVALUE1' WHERE ID=1");
java.sql.Savepoint sp1 = conn.setSavepoint();
try (Statement s = conn.createStatement())
s.executeUpdate("UPDATE ucaTest SET Field2='NEWVALUE2' WHERE ID=2");
conn.rollback(sp1);
conn.commit();
catch (Exception e)
e.printStackTrace(System.out);
有关使用 UCanAccess 的更多信息,请参阅
Manipulating an Access database from Java without ODBC
【讨论】:
以上是关于通过 JDBC-ODBC 桥使用保存点:UnsupportedOperationException的主要内容,如果未能解决你的问题,请参考以下文章