UCanAccess 错误 - net.ucanaccess.jdbc.UcanaccessSQLException:操作中的数据类型不兼容:;在 LIMIT、OFFSET 或 FETCH 中

UCanAccess error - net.ucanaccess.jdbc.UcanaccessSQLException: incompatible data type in operation: ; in LIMIT, OFFSET or FETCH

我是 UCanAccess 的新手,我正在使用它来代替将 Microsoft Office 从 32 位重新安装到 64 位或将 Netbeans 8.0.2 从 64 位重新安装到 32 位。

我正在 运行创建一个简单的程序来连接到一个小型数据库并显示它的结果;但是我 运行 遇到一个错误,即 Google 在我搜索时只有 5 个结果。

这是我的整个数据库 class:

package highscoresproj;

import java.io.File;
import java.sql.*;

public class DB
{

    private Connection connection;
    private PreparedStatement statement;
    private ResultSet resultSet;

    public DB()
    {
        //load driver

        try
        {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            System.out.println("Driver successfully loaded");
        } catch (ClassNotFoundException c)
        {
            System.out.println("Unable to load driver\n" + c);
        }

        //connect to database
        try
        {
            connection = DriverManager.getConnection("jdbc:ucanaccess://"+ getDatabaseLocation("HighScores.accdb")+ ";showschema=true");
            System.out.println("Connection successful");
        } catch (SQLException e)
        {
            System.out.println("Unable to connect\n" + e);
        }
    }

    public ResultSet query(String stmt) throws SQLException
    {
        statement = connection.prepareStatement(stmt);
        resultSet = statement.executeQuery();
        return resultSet;
    }

    public void update(String update) throws SQLException
    {
        statement = connection.prepareStatement(update);
        statement.executeUpdate();
        statement.close();
    }

    public static String getDatabaseLocation(String relativePath)
    {

        File dbFile = new File(relativePath);
        String path = dbFile.getAbsolutePath();
        path = path.replaceAll("\\", "/");
        System.out.println("DB Full path:\t" + path);
        return path;
    }
}

以及当我按下按钮显示最高分时 运行s 的方法:

private void btnDisplayMaxActionPerformed(java.awt.event.ActionEvent evt)                                              
{                                                  
    try
    {
        res = db.query("SELECT TOP Username, Score FROM tblUser INNER JOIN tblScores ON UserID = ID");
    } 
    catch (SQLException ex)
    {
        System.out.println("An error occured. Error Message:\n" + ex);
    }
}

当我 运行 程序并按下按钮时,我得到以下输出:

run:
Driver successfully loaded
DB Full path:   C:/Users/Aaron/Documents/Somerset College/IT/Java Book/Excersises/P148 Ex5/HighScoresProj/HighScores.accdb
Connection successful
An error occured. Error Message:
net.ucanaccess.jdbc.UcanaccessSQLException: incompatible data type in operation: ; in LIMIT, OFFSET or FETCH
BUILD SUCCESSFUL (total time: 11 seconds)

如果这是一个非常简单的错误,请原谅我,但我找不到任何地方专门提到它。谢谢!

您的 SQL 语法无效。 SELECT TOP 希望被告知您要返回的行数。如果您只想返回一行,请使用

SELECT TOP 1 Username, ...