在JDBC-ODBC桥中使用保存点:UnsupportedOperationException [英] Using savepoints with the JDBC-ODBC Bridge: UnsupportedOperationException

查看:162
本文介绍了在JDBC-ODBC桥中使用保存点:UnsupportedOperationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将NetBeans IDE与MS Access连接在一起,并且在进行事务处理时遇到此错误. 似乎不支持保存点...请指导我.

I have connected NetBeans IDE with MS Access and while doing a transaction I got this error. It seems that savepoints are not supported...Please guide me..

             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

The error is Statements created Queries created Connection created Error: java.lang.UnsupportedOperationException

推荐答案

JDBC-ODBC Bridge显然根本不支持保存点.但是, UCanAccess JDBC驱动程序确实支持未命名的保存点:

The JDBC-ODBC Bridge apparently does not support Savepoints at all. However, the UCanAccess JDBC driver does support unnamed Savepoints:

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的更多信息,请参见

For more information on using UCanAccess see

在不使用ODBC的情况下从Java操作Access数据库

这篇关于在JDBC-ODBC桥中使用保存点:UnsupportedOperationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆