"feature not supported" 在 UCanAccess 中执行 PreparedStatement 时出错

"feature not supported" error when executing a PreparedStatement in UCanAccess

我正在尝试使用 ResultSet(UCanAccess 支持)在 GUI 中填充我的组合框

package Vegan;

import java.sql.Connection;
import java.sql.DriverManager;


public class connectionString {

static Connection connection = null;

public static Connection getConnection()
{
    try
    {
        connection = DriverManager.getConnection("jdbc:ucanaccess://C:/Mo//MyDatabase1.accdb");
        System.out.println("---connection succesful---");
    }

    catch (Exception ex)
    {
        System.out.println("Connection Unsuccesful");
    }

    return connection;
}

package Vegan;

import static java.nio.file.Files.list;
import static java.rmi.Naming.list;
import java.sql.*;
import java.util.ArrayList;
import static java.util.Collections.list;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;


public class DB {


private static ResultSet rs = null;
private static PreparedStatement ps = null;
private static Connection connection = null;
private int StoreID;
private String userID;

public DB() {
    connection = connectionString.getConnection();
}


public void getCat(JComboBox box) throws SQLException {
    //String sql = "SELECT CategoryName FROM CategoryTbl GROUP BY CategoryName";


    String query = "SELECT CategoryName FROM CategoryTbl";
    ps = connection.prepareStatement(query);

    rs = ps.executeQuery(query);

    while (rs.next()) {
        String groupName = rs.getString("CategoryName");
        box.addItem(groupName);


    }

package Vegan;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import net.proteanit.sql.DbUtils;


public class UserMenu extends javax.swing.JFrame {

/**
 * Creates new form UserMenu
 */
public UserMenu() {
    try {
        initComponents();
        DB db = new DB();
        db.getCat(cmbCategory);


    } catch (SQLException ex) {
        Logger.getLogger(UserMenu.class.getName()).log(Level.SEVERE, null, ex);
    }
}

每次我尝试执行 UserMenu() 时都会收到此错误:

run:
---connection succesful---
Sep 11, 2016 11:04:47 PM Vegan.UserMenu <init>
SEVERE: null
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 feature not supported
at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:211)
at Vegan.DB.getCat(DB.java:203)
at Vegan.UserMenu.<init>(UserMenu.java:28)
at Vegan.UserMenu.run(UserMenu.java:179)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
at java.awt.EventQueue.access0(EventQueue.java:97)
at java.awt.EventQueue.run(EventQueue.java:702)
at java.awt.EventQueue.run(EventQueue.java:696)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
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:208)
... 17 more

我不知道这是什么原因造成的。我认为这是 ucanaccess 的问题? Link访问数据库以供参考:http://www53.zippyshare.com/v/DMLjdpDw/file.html

异常是由语句

引起的
rs = ps.executeQuery(query);

这是开始使用 PreparedStatement 对象的人的常见错误。

调用 .prepareStatement 时提供 SQL 命令文本,例如

ps = connection.prepareStatement(query);

因此,当需要执行 PreparedStatement 时,您只需调用

rs = ps.executeQuery();

由于我们从未使用参数调用 PreparedStatement 的 .execute... 方法,因此 UCanAccess JDBC 驱动程序抛出 "feature not supported" 异常。