Rockcoder
Rockcoder

Reputation: 11

Error message ORA-00933: SQL command not properly ended

I have a problem with this method:

public void insertIntoQueue(DTOQueue dtoQueue) { 
    DbConnection dbConnection = new DbConnection();
    Connection conn;
    try {
        conn = dbConnection.coneccion();
        String sql = " INSERT INTO PURE_ENC_QUEUE (queueId,queueName) values(?,?);";

        //creating PreparedStatement object to execute query
        PreparedStatement preStatement = conn.prepareStatement(sql);
        preStatement.setString(1, dtoQueue.getQueueId());
        preStatement.setString(2, dtoQueue.getQueueName());
        int result = preStatement.executeUpdate();

        DbConnection.closeConnection(conn);

        if(result > 0) {
            System.out.println("Insertado");
        } else {
            System.out.println("No insertado");
        }

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("done");
}

When I run it, throws the exception

java.sql.SQLException: ORA-00933: SQL command not properly ended

Any idea about the problem? Thank you!

Upvotes: 0

Views: 635

Answers (1)

Mick Mnemonic
Mick Mnemonic

Reputation: 7956

You need to remove the semicolon at the end of the query string, i.e.:

String sql = "INSERT INTO PURE_ENC_QUEUE (queueId,queueName) values(?,?)";

Also, it would be a good idea to refactor the code to use the try-with-resources statement.

Upvotes: 0

Related Questions