ORA-00928 missing SELECT keyword in Oracle

33,231

Solution 1

Without the single quotes, try

String query="insert into offer1(RCODE,OFFERNO,DAT) values(?,?,?)"; 

Solution 2

single quotes are for string literals not for identifiers only so you should remove it around the columnNames.

INSERT INTO offer1 (RCODE,OFFERNO,DAT) VALUES (?,?,?)

and use executeUpdate since you are not retrieving records which results a resultset.

from DOCS

boolean execute()

  • Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

ResultSet executeQuery()

  • Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

int executeUpdate()

  • Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.

Solution 3

I was running the same issue, and in my case the query was like this:

insert into Address (number, street, id) values (?, ?, ?)

The problem was caused by the number column name since number is a reserved keyword in Oracle, and the exception was "ORA-00928: missing SELECT keyword".

So, the number column name must be escaped, like this:

insert into Address ("number", street, id) values (?, ?, ?)

and everything works fine now.

Solution 4

Please try this

String query="insert into offer1(RCODE,OFFERNO,DAT) values(?,?,?)"; 

Solution 5

Try Statement.executeUpdate instead of executeQuery.

Share:
33,231
Linga
Author by

Linga

Filemaker developer, Web application developer and Software developer.

Updated on July 21, 2022

Comments

  • Linga
    Linga almost 2 years

    I'm using the following code to insert data. But I'm receiving an error as "ORA-00928: missing SELECT keyword"

    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    java.sql.Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxx.xxx.x.xxx:xxxx:xxxx", "xxxx", "xxxx");
    String query="insert into offer1('RCODE','OFFERNO','DAT') values(?,?,?)"; 
        PreparedStatement ps=conn.prepareStatement(query);
        ps.setString(1,r_code);
        ps.setString(2,offerno);
        ps.setDate(3,sqlDate);
        ResultSet rs=ps.executeQuery();
        out.println("data inserted");
    }catch(Exception e)
     {
         out.println(e);
     }
    

    I can't see any errors in this code. If someone finds, please tell me what is the mistake and how to solve it?

  • Viru
    Viru about 11 years
    Please explain it in detail!
  • masterxilo
    masterxilo over 9 years
    The real solution would of course be for the database to give a correct error message, this is just a workaround.