• 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

Database Starnge behaviour

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear ALL,

i'm trying to access some data from
my database but i have A strange behavior and hope to help me to understand
what is happening

when i try to retrieve column data form DB and print it

it will be printed

but when i try to assign it to a String

i get this exception "NO Data Found"

Query=" select * from CPM_DEST";

st = conn.createStatement();

rs=st.executeQuery(Query);


while(rs.next())

{


System.out.println(rs.getString("DESTNAME")); //printwith no problem


String x=(String)rs2.getString("DESTNAME");//here i get the exception

}



Whta's happining..?

Thanks®ards

essam
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. what is rs2 ?
2. you don't need to cast as getString returns a String
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. what is rs2 ?

sorry it's just amistake in writing .it's supposed to be rs

2. you don't need to cast as getString returns a String

just i'm trying to find asolution you can remove teh casting
but the problem still
 
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
You can only read each value from the Resultset once, after that nothing is guaranteed. It's in the API somewhere but I'd have to go look.
 
David O'Meara
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
"Essam AbdelAziz9",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

thanks,
Dave
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:
You can only read each value from the Resultset once, after that nothing is guaranteed. It's in the API somewhere but I'd have to go look.



Yeah Dave i got you point inside jdbc basic on java.sun.com
"each column should be read only once"
here is a URL http://java.sun.com/docs/books/tutorial/jdbc/basics/retrieving.html look at last line in first paragraph inside the heading of Using the getXXX Methods
 
David O'Meara
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
Or you can check the API for ResultSet

The ResultSet interface provides getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. 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.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic