Search code examples
javasqloracle-databasesqlexception

java.sql.SQLException: ORA-01747


When i am running the following SQL query i am getting the following error:

java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification

String strQuery = "UPDATE themed_night SET theme_night_name = ?, theme_night_date = TO_DATE(?, 'dd-MM-yy'), theme_night_description = ?, WHERE theme_id = ?";
        PreparedStatement stmt = conn.prepareStatement(strQuery);//prepare the SQL Query
        stmt.setString(1, title);
        stmt.setString(2, output);
        stmt.setString(3, details);
        stmt.setString(4, themeID);

Is my SQL query syntax correct? I have double checked the columns and i have typed the correct names.


Solution

  • You have an extra comma in your statement. The correct statement should be

    String strQuery = "UPDATE themed_night SET theme_night_name = ?, theme_night_date = TO_DATE(?, 'dd-MM-yy'), theme_night_description = ? WHERE theme_id = ?";
    

    Also, you might need to enclose some values with single quotes (though I'm not sure about that)