• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getString() in ResultSet

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a code that uses JDBC to retrieve data from Oracle database. e,g,
ResultSet rt = statement.executeQuery(sql);
String s = rt.getString("User_ID") // it's 'N/A'.
if( s.equals("N/A")
System.out.println("....");
It is not equal! How come? It doesn show as N/A! Is this a data type conversion thing?
Thanks,
Kelly
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you move the result set forward one first?

Dave
 
Kelly Adams
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Yes. I did. I used

while( rt.next())
String a = rt.getString("user_ID");....
And when I print out a, it did show up as N/A. But it deson't equal to N/A. When I used the compraeTo() method in String, it should a positive integer 97. Any idea?
Thanks,
Kelly
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tried your example and it works fine.
Here are the SQLs:
insert into temp(User_Name)
values('N/A');
I used JDBC to retrieve the User_Name and I get the String "N/A".
Suresh Selvaraj
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe the problem is extra spaces.
Try:
String s = null;
while( rt.next()) {
s = rt.getString("user_ID");
if (s != null) {
s = (s.trim()).toUpperCase();
}
if ( s.equals("N/A") ) {
System.out.println("Equal");
} else {
System.out.println("NotEqual s='"+s+"'");
}
}
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your field is varchar(N), then equals("N/A") should return true (provided that the field actually contains that string, that your query is right, etc). However, if your field is char(N), N<>3, then it won't as it'll be space-padded.
- Peter
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Battist may be right.
Print out the string fetched and decide your action from there.
System.out.println("User_ID = '"+rt.getString("User_ID") +"'");
[ February 19, 2003: Message edited by: kundi kx ]
reply
    Bookmark Topic Watch Topic
  • New Topic