• 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

different methods...

 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println(rs.getString("a") + " " + rs.getBoolean("a"));
System.out.println(rs.getString("b") + " " + rs.getBoolean("b"));
System.out.println(rs.getString("c") + " " + rs.getBoolean("c"));
System.out.println(rs.getString("d") + " " + rs.getBoolean("d"));



ok in this example of resultsets, what exactly do getString,getInt, and get boolean do?


Justin
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The various getTYPE("xyz") methods return attribute "xyz" as an object of a particular type. JDBC is fundamentally String-based, meaning that's what comes over the wire. So in order to use different types in the application, you need to tell it how to interpret the string. getString probably does nothing but hand over what it got from the DB. getInt needs to parse the string to an integer (which will fail, or give you some default, if the value isn't a number). And so on.

I wouldn't rely on these methods to be able to make sense of types other than the ones they are meant to be used with. E.g., if you use getBoolean on an integer field, you may not get an exception, but the result may not be what you're expecting either.
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rs.getString("a") gets a string from the result set identified by "a".
rs.getBoolean("a") gets a boolean value identified by "a". I think you can figure out what getInt does.

Those identifiers represent columns in a table. So if I have a table called Cars, and each row in the table holds make, model, color, and year of a car. After querying the database, I could get the values from the resultset by doing something like:
rs.getString("make")

EDIT: Checking out the API might help you understand. Then again, it might give you information overload...
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html
[ August 13, 2007: Message edited by: Chad Clites ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic