Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 24th, 2005, 03:31 PM
wbmoore wbmoore is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 wbmoore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 33 sec
Reputation Power: 0
java, weblogic, oracle, PreparedStatement

I am having difficulty getting prepared statements to work in Weblogic 8.1. I have code that looks like this:

//this works
String keyString = "keyID";
String sql = "select * from myTable where myKey = '"+ keyString + "'";
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
i = 0;
while(rs.next()){
System.out.println("row["+i+"] = ["+rs.getString(1) + "]");
i++;
}
ps.clearParameters();
rs.close();

//but this returns no data:
sql = "select * from myTable where myKey = ?";
ps = con.prepareStatement(sql);
ps.setString(1, keyString);
rs = ps.executeQuery();
while(rs.next()){
System.out.println("row["+i+"] = ["+rs.getString(1) + "]");
i++;
}
rs.close();

The 2nd code fragment returns an empty result set, while the first returns me my data. The only difference is whether I use a '?' and parameters or just put the data into single quotes and not use a parameter to the PreparedStatement. But that kind of defeats the purpose of PreparedStatements. I'm using weblogic 8.1. Java 1.4.2 and Oracle 9i.

What am I missing or not configuring correctly? How do I make the PreparedStatement work correctly w/ weblogic 8.1?

Thanks,
Walter Moore

Reply With Quote
  #2  
Old July 27th, 2005, 01:54 PM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
I've read and reread your code and it seems all right to me. But I'd suggest you to put the working code in comment and let the second code (with the parameters and the ps.setString()) do its work.
I have the feeling it could be possible that the cursor of the resultset does not give any records since it already has found all the records of the database.
It's just a feeling but I'm very interested to hear if you get any records if you put the working part of your code in comment.

Reply With Quote
  #3  
Old July 27th, 2005, 09:21 PM
wbmoore wbmoore is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 wbmoore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 33 sec
Reputation Power: 0
found the solution!

It turns out that the DB field (myKey) is CHAR(3). Oracle pads automatically when you do not use paramters. So in the first case it would trim the keyID. So if the actualy key I was looking for was 'US ', and I passed in 'US', it would pad so that it was 'US '.
BUT, when you use parameters, no such padding occurs. This is an inconsistency with the oracle driver. Once I padded the key with spaces to match what was in the DB, or RTRIM(myKey), data was returned.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > java, weblogic, oracle, PreparedStatement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway