0

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!

Rockcoder
  • 11
  • 1
  • 5

1 Answers1

0

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.

Mick Mnemonic
  • 7,808
  • 2
  • 26
  • 30
  • Thank you! but, when I do that, the line: _PreparedStatement preStatement = conn.prepareStatement(sql);_ is blocked and the program does not continue, but does not throw exceptions either. But when I do a test with string value in the sentence _"INSERT INTO PURE_ENC_QUEUE (QUEUEID, QUEUENAME) VALUES('nuevaColaId2','nuevaColaNombre2')";_, it works. I print the line with the vars value, and have a valid values. – Rockcoder Nov 17 '19 at 19:00
  • That problem shouldn't be related to the suggested fix. You could check if there is a problem with your app server/database and maybe try a clean install/restart. – Mick Mnemonic Nov 18 '19 at 09:58
  • Thank you! The problem was generated from database. When I did a query from SQL Developer. – Rockcoder Nov 19 '19 at 01:39
  • If this answered your question, you could mark the answer as accepted using the tick mark symbol. – Mick Mnemonic Nov 19 '19 at 08:10