This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to use Prepared Statement with Oracle? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to use Prepared Statement with Oracle?" Watch "How to use Prepared Statement with Oracle?" New topic
Author

How to use Prepared Statement with Oracle?

Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
I have the following code in my program:
sqlGLanalysisCode2 = "select gl_analysis_code_2 FROM gl_accounts where account_number = ? ";
statGLanalysisCode2 = oconn.prepareStatement(sqlGLanalysisCode2);
statGLanalysisCode2.setString(1, strGL_code);
rsGLanalysisCode2 = statGLanalysisCode2.executeQuery();
I found the above code will work if I use the sybase server. However, if I use oracle, it seems to me that the ? never gets the value from the variable.
Thanks for your help!
Mindy
David Freels
Ranch Hand

Joined: Feb 01, 2001
Posts: 102
I have looked at your code and compared it with some code I have written for Oracle and there should not be a problem. Maybe you should debug and check the value you are setting and make sure there is something in it.
David
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Thanks David! You are right that there is nothing wrong with my code. I do fix my problem. I found out something very different between Sybase and oracle. In oracle, if you create a field with fix length, and the field value does not take up the defined space, oracle will append white space at the end of the field value. In my sql statement, I use "=" operator, and my field value never takes up the field length, so that is why it could not return a recordset, but if I use like operator or trim the database field that fix all of the problem.
Thanks!
Mindy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Prepared Statement with Oracle?
 
Similar Threads
what kind JDBC driver do I need ?
newbie to both java and oracle.. how do i ...
String class can't find split method: wrong java version?
CallableStatement * setObject
No proxy with session.load() instead it does a database hit - Why?