I am trying to run an application that is talking to an oracle DB. when I run the application, enter the value into the JTextField, then hit the submit button, I get the error: java.sql.SQLException: ORA-00923: FROM keyword not found where expected
I have checked the SQL, it is correct before anybody ask. If I place single quotes around the ? for my prepared statement, I get the error "invalid column index" take the quotes out, I get the ORA-00923 error. I know it works because if I modify the code and run it with a value in place of the ? like a regular SQL statement it returns the values that are to fill out in my 15 JTextFields of my swing application. any ideas or help would be much appreciated! help!
Here is the code for the JDBC connection class:
I printed the SQL statement by itself, entered a value in place of the ? and used TOAD to run it, I had to put a single quotes around the value, once I did that it returned the data that I want.
next I went back to the code that worked before returning the same data. it is below. the one thing that I found different was that this code was before I put in java to call the JTextField to enter the value, this code has the value in place already, when I hit my submit button, it runs this class and returns the data.
This problem is quite simple. If I may have faced this problem, then I shall print the query and paste it in DBVisualizer and use query formatting feature. After using it, the query will be formatted properly and I can inspect very easily.
Please try my suggestion.
From your test in TOAD, you already know that the query expects a string, because you had to provide single quotes in TOAD.
Joined: Mar 12, 2009
when I change it to setString I get this error message:
Exception in thread "Thread-2" java.lang.Error: Unresolved compilation problem:
The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, int)
In the code that you didn't like to much I noticed that the beginning of the SQL statement looked like this:
In the code now that looks better the beginning of the SQL looks like this:
could that be the cause of the error? Eclipse and JDeveloper both want me to setLong.
I just described the table po_headers_all. Segment1 is VARCHAR2(20).
This should be correct for binding a varchar2:
....Distinct ....could that be the cause of the error?
Eclipse and JDeveloper both want me to setLong.
Eh? po.po_headers_all.SEGMENT1 is a varchar2.
Clueless at this point.
Joined: Mar 12, 2009
Thanks for all of your help! I got it figured out. it is working nicely now, what the problem was, was that the String for number of columns to return the data to was also the same string that I was trying to pull from. (hope that makes sense)
I put in this code,
POData is the name of the JTextField in another class, the same one I wanted to pull the variable from to place into the sql statement. I just had to define the string, and the method of that string.
subject: java.sql.SQLException: ORA-00923: FROM keyword not found where expected