sng
sng

Reputation: 129

SQL Command not properly Ended

Tried running a java method that runs this oracle SQL query

String query =
            "SELECT count(*) " +
            "FROM TASK t " +
            "WHERE t.TASK_ID = ? ";

I keep getting SQL Command not properly Ended

Printed the string and got this output SELECT count(*) FROM TASK t WHERE t.TASK_ID = ?

*edited to reflect new changes, the method basically looks for the taskID and if it exists return true, otherwise false.

public boolean loadTaskId(Integer taskId) throws SQLException{

    int count = 0;

    String query =
            "SELECT count(*) " +
            "FROM TASK t " +
            "WHERE t.TASK_ID = ?";

    OraclePreparedStatement stmt = prepareStatement(query);
    stmt.setInt(1, taskId);
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) { // only load the first one
        count = rs.getInt(1);
    }
    stmt.close();
    if ( count == 0) {
        return false;
    } else {
        return true;
    }
}

Upvotes: 1

Views: 12276

Answers (3)

sng
sng

Reputation: 129

Figured out whats wrong, I didn't delete the .jar file in the library and it had some name conflicts going on and wasn't rebuilding. *slaps my own head

Upvotes: 0

Anush
Anush

Reputation: 1050

String query =
            "SELECT count(*) " +
            "FROM TASK t " +
            "WHERE t.TASK_ID = ?";

You did not add spaces

Upvotes: 1

JW8
JW8

Reputation: 1506

You might want to modify your SQL statement to include some spaces:

String query =
        "SELECT count(*) " +
        "FROM TASK t " +
        "WHERE t.TASK_ID = ?";

That's probably the problem. You can print the string out to System.out to confirm.

Upvotes: 9

Related Questions