gpt4 book ai didi

java - UCanAccess 错误 - net.ucanaccess.jdbc.UcanaccessSQLException : incompatible data type in operation: ; in LIMIT, OFFSET 或 FETCH

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:20:40 25 4
gpt4 key购买 nike

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

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

这是我的整个数据库类:

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;
}
}

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

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, ...

关于java - UCanAccess 错误 - net.ucanaccess.jdbc.UcanaccessSQLException : incompatible data type in operation: ; in LIMIT, OFFSET 或 FETCH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29757712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com