Ucanaccess SQL异常:不支持的功能(Access和Netbeans)

时间:2015-07-14 03:03:12

标签: java ms-access netbeans sqlexception ucanaccess

我几天来一直在研究这个问题,并决定在这里提出这个问题,看看是否有人可以帮助我指出正确的方向。

我正在尝试使用MS Access 2013表中的数据填充Netbeans 8.0.2程序中的组合框。

我正在使用最新的“Ucanaccess”及其所有必要的组件来获取两者之间的连接,并且我可以告诉它连接是好的。但是,当我运行程序时,会弹出一条错误异常消息,显示为:

net.ucanaccess.jdbc.UcanaccessSQLException: feature not supported

就是这样 - 没有其他字母,字符,数字......没有。

我老实说迷路了。有谁知道我为什么会收到这条异常消息?

另外,我在Mac上运行它,但是我使用parallels并且实际上是在Microsoft Windows 7虚拟平台上运行它。从那时起它一直没有给我任何麻烦。 64位。

这是我编码的内容。

import java.sql.*;
import javax.swing.*;

public class NewJFrame extends javax.swing.JFrame {
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    private void FillCombo() {
        String sql = "Select [Description] from [Doors]";
        try {
            String driver = "net.ucanaccess.jdbc.UcanaccessDriver";
            Class.forName(driver);
            conn = DriverManager.getConnection("jdbc:ucanaccess://C:/Test/DB.accdb");
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery(sql);

            while (rs.next()) {
                String nme = rs.getString("Description");
                cmb1.addItem(nme);
            }
            conn.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,e);
        }            
    }

    /**
     * Creates new form NewJFrame
     */
    public NewJFrame() {
        initComponents();
        FillCombo();            
    }

更新:

net.ucanaccess.jdbc.UcanaccessSQLException: feature not supported
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:202)
    at NewJFrame.FillCombo(NewJFrame.java:26)
    at NewJFrame.<init>(NewJFrame.java:50)
    at NewJFrame$2.run(NewJFrame.java:117)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.sql.SQLFeatureNotSupportedException: feature not supported
    at org.hsqldb.jdbc.JDBCUtil.notSupported(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeQuery(Unknown Source)
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:199)
    ... 17 more

1 个答案:

答案 0 :(得分:6)

您需要致电PreparedStatement#executeQuery()而不是PreparedStatement#executeQuery(String)