Problem in executing Query of resultset Object for JDBC Connectivity

I am facing the GRAND PROBLEM in executing query from resultset object for mu JDBC work….
please help

problem appears in this statement
resultset = statement.executeQuery(query);

this gives this error

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 unexpected end of statement:  required: (
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:218)
    at DB.AuthorsManager.viewAuthor(AuthorsManager.java:26)
    at UI.Client.main(Client.java:268)
Caused by: java.sql.SQLSyntaxErrorException: unexpected end of statement:  required: (
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source)
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:216)
    ... 2 more
Caused by: org.hsqldb.HsqlException: unexpected end of statement:  required: (
    at org.hsqldb.error.Error.parseError(Unknown Source)
    at org.hsqldb.ParserBase.unexpectedTokenRequire(Unknown Source)
    at org.hsqldb.ParserBase.readThis(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableFunctionDerivedTable(Unknown Source)
    at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
    at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
    at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 5 more

This is Authors Manager Class whose method viewAuthor is facing error

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class AuthorsManager {   
    public static  void viewAuthor(){
        int col1 = 0;       
        String col2=null;
        DBConnect dbconnect = new DBConnect();
        dbconnect.getConnection("this.accdb");
        Statement statement = dbconnect.getStatement();     
        String query = "SELECT * from Table";
        try {
            ResultSet resultset=null;
            resultset = statement.executeQuery(query);
            col1 = resultset.getInt("id");          
        }
        catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally {
            DBConnect.disconnect();
        }
    }
}

and this is DBConnect Class which is Connecting and giving statement object to AuthorsManager class

DBConnect Class


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnect {

    private static Connection connection = null;
    private static Statement statement = null;

    public static void getConnection(String path) {

        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            connection = DriverManager.getConnection("jdbc:ucanaccess://" + path);
            statement  = connection.createStatement();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        } 



    }

    public static Statement getStatement() {
        // TODO Auto-generated method stub
        return statement;
    }

    public static void disconnect() {
        try {
            connection.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

Archive from: https://stackoverflow.com/questions/59064088/problem-in-executing-query-of-resultset-object-for-jdbc-connectivity

Leave a Reply

Your email address will not be published. Required fields are marked *