java.sql.SQLException: ORA-00928: missing SELECT keyword. when inserting record to DB using JDBC
Solution 1
I can spot two problems:
- No need for single quotes around column names. But you may wrap it in double quotes. It is necessary if you are using reserved keywords for column names or table names. Here
DATE
. - You need a space before
VALUES
.
So you need to change insertStmt
to somthing like this:
String insertStmt = "INSERT into " +
"MY_TABLE(RECORD_TYPE, FILE_TYPE, \"DATE\", BATCH_NO, RECORD_COUNT) " +
"VALUES(?, ?, ?, ?, ?);";
Solution 2
You need to change the SQL
statement. (Never use reserved words as identifiers)
String insertStmt = "INSERT into \"MY_TABLE\" (RECORD_TYPE,FILE_TYPE,
\"DATE\",BATCH_NO,RECORD_COUNT) VALUES (?, ?, ?, ?, ?)";
Use "
(double quotes) to escape the reserved words/keywords.
Solution 3
Print insertStmt String in Console and try to fire it in directly backend. It gives you exact error in backend. It seens some spacing or syntax error.
Solution 4
I just came to this page while searching for ORA-00928, and I'd like to note that my problem was an extra comma at the start of the column list:
INSERT INTO redacted.redacted
(
, redacted_id -- The comma at the start of this line will trigger ORA-00928.
, another_redacted_id
, redacted1
, redacted2
, redacted3
, created_at
, created_by
, changed_at
, changed_by
)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)
chip
Updated on July 29, 2022Comments
-
chip almost 2 years
I get an error when I try to insert some rows to a db. so here is the code
try { String insertStmt = "INSERT into " + "MY_TABLE('RECORD_TYPE', 'FILE_TYPE', 'DATE', 'BATCH_NO', 'RECORD_COUNT')" + "VALUES(?, ?, ?, ?, ?);"; PreparedStatement pstmt = super.con.prepareStatement(insertStmt); pstmt.setString(1, input[0]); pstmt.setString(2, input[1]); pstmt.setString(3, input[2]); pstmt.setString(4, input[3]); pstmt.setString(5, input[4]); System.out.println("Insert rows : " + pstmt.executeUpdate()); } catch (SQLException sqle) { System.out.println(sqle.getMessage()); sqle.printStackTrace(); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } finally { con.close(); }
and everything on the db is of varchar type, double checked the columns (they all are the same name), took out the quotes off the column name (same result) no success. to add it up, the error message is not very helpful.
any suggestions would be appreciated.
-
chip over 12 yearsyep, i tried inserting a record from the db ide and knew that there were some syntax errors. thanks for the answer jwalin. appreciate it
-
chip over 12 yearshey man, I was about to answer that here. yep, the date column need to be surrounded by double quotes and then escaped. thanks for the answer :D :D :D
-
KV Prajapati over 12 yearsRead the OP and title - It is all about oracle.