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:
No it's not.
have checked the SQL, it is correct before anybody ask.
Why don't you print the sql statement and have a look at what is wrong?
Can you retry that? Please print both sql statements from your java code, and show them in this post. We can compare them.
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
I think it fails at the first + on line 33.
Why do you put ); on line 88? Where are these brackets opened? Why the semicolon?
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.
Try to replace
+ " pha.segment1 = '907878' AND "
by (indeed, without single quotes)
+ " pha.segment1 = ? AND "
Then try running it with this fixed parameter binding:
If it now returns a value, you can start using the input from your textfield:
Then I added the prepared statement code:
when I click the submit button, I get the following error:
java.sql.SQLException: ORA-01008: not all variables bound
Not too sure what that means? If I place the value in with single quotes, it works and returns my data.
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.
This should be correct for binding a varchar2:
....Distinct ....could that be the cause of the error?
Eh? po.po_headers_all.SEGMENT1 is a varchar2.
Eclipse and JDeveloper both want me to setLong.
Clueless at this point.
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.