Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

ResultSet

 
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


the above code gives me an sqlexception because the statement "rs.getString("Book_Id")" is called twice, if you see, i had to change the second call to getString("Book_Id") with this code:


why is this like this?i mean as long as i am not calling rs.next(), i should be able to access a column in a given record as many times as i want...right?

[edit]Delete excess whitespace. CR[/edit]
[ August 29, 2008: Message edited by: Campbell Ritchie ]
 
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rs1 = st1.executeQuery("select Author_Name from Authors where Book_Id='"+ rs.getString("Book_Id")+"'");

why don't you use

rs1 = st1.executeQuery("select Author_Name from Authors where Book_Id='"+ bookObject.getBookID()+"'");

I hope that there will an accessor method for the ID field in the Book class that you have created.

result set is like a pointer. once you get it ahead of one column you can't get back to that column....This means that you cannot go backwards in column list.....

If there is a way to get to one column again I don't know it....
 
Marshal
Posts: 75650
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know, but I think your topic will sit more happily on the JDBC thread, so I shall move it there.

Please tell us more about the Exception; what was its message, its SQL state and its error code.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The javadoc for ResultSet recommends you don't do it, so it's probably something in the database that doesn't like it. It may work okay on other databases.

For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.

 
Ankit Garg
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's the problem of the Database Connection Driver.....
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic