UCanAccess error - net.ucanaccess.jdbc.UcanaccessSQLException: Incompatible data type at work :; in LIMIT, OFFSET or FETCH

I am new to UCanAccess and am using it instead of reinstalling Microsoft Office from 32-bit to 64-bit or Netbeans 8.0.2 from 64-bit to 32-bit.

I am running a simple program to connect to a small database and display the results from it; however I ran into the error that google only has 5 results when searching.

Here is my entire DB 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;
    }
}

      

And the method that runs when I click the button to display the top scores:

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

      

When I run the program and click the button, I get the following output:

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)

      

Please forgive me if this is a very simple error, but I couldn't find it anywhere, especially mentioning it. Thank!

+3


source to share


1 answer


SQL syntax is invalid. SELECT TOP

expects to be given the number of rows you want to return. If you only want to get one line then use



SELECT TOP 1 Username, ...

      

+2


source







All Articles