我是UCanAccess的新手,并且正在使用它来代替将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)
如果这是一个非常简单的错误,请原谅我,但我找不到任何具体提到它的地方。谢谢!
答案 0 :(得分:2)
您的SQL语法无效。期望告诉SELECT TOP
您想要返回的行数。如果您只想返回一行,请使用
SELECT TOP 1 Username, ...