Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Prepared Statement with Oracle?

 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic