我是 UCanAccess 的新手,我正在使用它来代替将 Microsoft Office 从 32 位重新安装到 64 位或将 Netbeans 8.0.2 从 64 位重新安装到 32 位。
我正在运行一个简单的程序来连接到一个小型数据库并显示它的结果;但是我遇到了一个错误,当我搜索时谷歌只有 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)
如果这是一个非常简单的错误,请原谅我,但我找不到任何特别提到它的地方。谢谢!