aspose file tools*
The moose likes JDBC and the fly likes Database Starnge behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Starnge behaviour" Watch "Database Starnge behaviour" New topic
Author

Database Starnge behaviour

Essam AbdelAziz
Ranch Hand

Joined: Mar 10, 2007
Posts: 34
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
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

1. what is rs2 ?
2. you don't need to cast as getString returns a String


[My Blog]
All roads lead to JavaRanch
Essam AbdelAziz
Ranch Hand

Joined: Mar 10, 2007
Posts: 34
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
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Mar 06, 2001
Posts: 13459

"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
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Starnge behaviour