1

I am getting the sql command not properly ended when hiting this line below.

stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);    
String updateQ = "update ANI_999 set First_Name = '"+d.getName()+"', HouseNo = '"+d.getAddr1()+"', Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, Indicator_Sourcefile_iCARE1='"+currentFile+"' where CALLER_ID = '"+msisdn+"' ";

int result = stmt.executeUpdate(updateQ);
conn.commit();
conn.close();`

I keep getting ORA-00933: SQL command not properly ended.

This is what updateQ statement looks like:

update ANI_999 set First_Name = 'ZAHARAH BINTI ABDUL RAHMAN', HouseNo = 'No. JKR6357,', Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, Indicator_Sourcefile_iCARE1='ICAREP_ANI_SVCPROF_20120402_002.DAT' where CALLER_ID = '058011726' 

here is the full function:- Kindly please refer this symbol "<<"

public void updateRecord(icData d, String msisdn) {
   Connection conn = null;
   Statement stmt = null;
   int recCtr = 0;

try {
   conn = ds.getConnection();

       stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); 
       String updateQ = "update ANI_999 set First_Name = '"+d.getName()+"', HouseNo = '"+d.getAddr1()+"', Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, Indicator_Sourcefile_iCARE1='"+currentFile+"' where CALLER_ID = '"+msisdn+"' ";


   int result = stmt.executeUpdate(updateQ);
   conn.commit();
   conn.close();
}
catch(SQLException ex) {

    logger.error("iCARE:Error : " + ex.getMessage()); <<this line show me that error>>

}
finally {
    try {if (stmt != null) stmt.close();} catch (SQLException e) {}
        try {if (conn != null) conn.close();} catch (SQLException e) {}
}
}
12
  • 2
    Have you tried printing the sql and running on the SQL prompt. If there is missing quotes, it will be easy to find. Commented May 23, 2012 at 5:18
  • Whats the value in currentFile. This might be containing some slash causing problem Commented May 23, 2012 at 5:20
  • i am sorry, what do you mean by printing the sql?..I already check the "result" value, it show the number, means the sql is work properly but i do not know why I keep getting this error.ORA-00933: SQL command not properly ended. Commented May 23, 2012 at 5:23
  • If any of the variables from which you build the update query contains a single quote it will cause this error. More serious is the fact that this technique of building a statement directly from user input is vulnerable to "SQL Injection" (Google it) and is a huge security hole that should never appear in production code. Commented May 23, 2012 at 5:25
  • 1
    @SitiHaslinaMohdZulkafli - Hmm. Not just error message but statcktrace. check my answer, if it helps. Commented May 24, 2012 at 0:50

3 Answers 3

1

You should use a PreparedStatement:

String updateQ = "update ANI_999 set First_Name = ?, HouseNo = ?, " +
       "Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, " +
       "Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, " +
       "Indicator_Sourcefile_iCARE1=? where CALLER_ID = ? ";
PreparedStatement prep =  conn.prepareStatement(updateQ, 
    ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); 
prep.setString(1, ...);
prep.setString(2, ...);
prep.setString(3, ...);
int result = prep.executeUpdate(updateQ);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you..your suggestion is really useful. I am really appreciate it..Thanks..:)
1

ERROR: ORA-00933: SQL command not properly ended.
CAUSE: You tried to execute an SQL statement with an inappropriate clause.

Instead of just catching the error message, you should have caught the stacktrace in the catch block. That gives you line number of your statement execution that has root cause.

Change

logger.error("iCARE:Error : " + ex.getMessage()); // <<this line show me that error>>

To

ex.printStackTrace(); // <<this line show me that error>>

Alternatively you can try the following code change and see if it works for you.

There is a chance that your input to update statement has some un-escaped characters and hence causing an error. Change your Statement object to PreparedStatement and see if it is resolved.

try {  
  ...
  String updateQ = "update ANI_999"  
    + " set First_Name = ?, HouseNo = ?,"  
    + " Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2,"  
    + " Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1,"  
    + " Indicator_Sourcefile_iCARE1=?"   
    + " where CALLER_ID = ?";  

  PreparedStatement pstmt = conn
   .createStatement( updateQ, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY );  
  pstmt.setString( 1, d.getName() );  
  pstmt.setString( 2, d.getAddr1() );  
  pstmt.setString( 3, currentFile );  
  pstmt.setString( 4, msisdn );  

  // print what the query actually holds. Not sure if all drivers support this.
  System.out.println( "DEBUG: query: " + pstmt.toString() );

  int result = pstmt.executeUpdate( updateQ );  
  System.out.println( "DEBUG: Update Result: " + result );
  ...  
} catch ( Exception ex ) {  
  // logger.error( ...  
  ex.printStackTrace(); // keep this until debugged  
}  
...

3 Comments

Thank you Ravinder, when I try this its working but need a bit modification. Anyway, thanks for this idea. Really appreciate it.Yeyy!!..:)
@SitiHaslinaMohdZulkafli - Did you trace the error stack? If yes, post it in your query.
Ok, I will update it. I cannnot "upvote" because my reputation only 11. I need to increase my reputation to 15 than I can do that. I am sorry..:)
0

You can get a ORA-00933, if you are inserting your variable strings into a command string e.g.

string inputName = "Rose";
string sqlCmd = "SELECT * FROM mytable WHERE brand_name = '" + inputName +"'";

the above works fine - but if:

string inputName = "Rose's";

The resulting SQL is SELECT * FROM mytable WHERE brand_name = 'Rose's' which throws ORA-00933, so remember to escape your single quotes!

If you are using a LIKE clause then you might have to start thinking about escaping %'s. One of the reasons people suggest using prepared statements is so you don't have to worry about escaping this things.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.