• 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

problem in extracting values from ResultSet

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the result set to extract data from the database..
now when I execute the query and take the result from one of the column of the table
String a=rs.getString("f_access");
and now without altering the resultset I again access the rest of the columns
System.out.println(rs.getString("trans_no"));
System.out.println(rs.getString("stud_id"));
System.out.println(rs.getString("f_name"));
System.out.println(rs.getString("f_size"));
System.out.println(rs.getString("trans_date"));
System.out.println(rs.getString("f_access"));
including the column "f_access" again...
but it gives me the following error
java.sql.SQLException: [Oracle][ODBC]Invalid column number <1>.
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing more of my code to make myself clear
the structure of the table is
TRANS_NO NOT NULL VARCHAR2(4)
STUD_ID VARCHAR2(6)
F_PATH VARCHAR2(100)
F_NAME VARCHAR2(50)
F_FILE BLOB
F_SIZE VARCHAR2(10)
TRANS_DATE DATE
A_TYPE VARCHAR2(1)
F_ACCESS VARCHAR2(4000)
F_DUPLICATE NUMBER(3)
and the code is:--
cmd="select trans_no,stud_id,f_name,f_size,trans_date,f_access from transaction where a_type='S'";
rs=stmt.executeQuery(cmd);
rs.next();
String a=rs.getString("f_access");
System.out.println(a);///I checked the value here of a is "333"
if(a.equals("333"))
{
System.out.println(rs.getString("trans_no"));
System.out.println(rs.getString("stud_id"));
System.out.println(rs.getString("f_name"));
System.out.println(rs.getString("f_size"));
System.out.println(rs.getString("trans_date"));
System.out.println(rs.getString("f_access"));
}
and the excpetion is as given above....
now if I take out the step
********String a=rs.getString("f_access");*******
then it gives me the result...
thanx for the reply...
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Bib,
cmd="select trans_no,stud_id,f_name,f_size,trans_date,f_access from transaction where a_type='S'";
rs=stmt.executeQuery(cmd);
rs.next();
String a=rs.getString("f_access");
System.out.println(a);///I checked the value here of a is "333"
if(a.equals("333"))
{
System.out.println(rs.getString("trans_no"));
System.out.println(rs.getString("stud_id"));
System.out.println(rs.getString("f_name"));
System.out.println(rs.getString("f_size"));
System.out.println(rs.getString("trans_date"));
System.out.println(rs.getString("f_access"));
}
and the excpetion is as given above....
now if I take out the step

Y dont u replace System.out.println(rs.getString("f_access")); with System.out.println(a);
You have already assigned rs.getString("f_access") to a, so why not use it.
Hope this helps.

Regards,
Piyush
 
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
"Bib Bob"
Change your name to comply with the naming convention or your account will be locked.
"harmanjeet s" was unacceptable (but definitely the closest)
"IT Revolution" wasn't acceptable.
"Bib Bob" is not acceptable.
Read the naming policy. Your name must not be obviously fictitious and must be your first name, a space, then your last name.
It appears that the moderators are spending too much time telling you to change your name and this is restricting the time they have to answer yours and others questions. We're all volunteers around here.
We want to help you and we want to answer your questions, so how about cutting us some slack and following just about the only rule we have.
thanks,
Dave.
[ July 14, 2002: Message edited by: David O'Meara ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know, from what I know you can only access a column from a ResultSet once. Can anybody confirm this? When I tryd to access the same column 2 times I get an exception the second time, even though the Resultset is still alive. I don't know if this is fixed with JDBC 3.0 (sdk 1.4.0).
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex, you are correct. A resultset's column can only be accessed once. At least as far as JDBC 2.0 is concerned.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bosun Bello:
Alex, you are correct. A resultset's column can only be accessed once. At least as far as JDBC 2.0 is concerned.

To expand on this point, you are guaranteed to be able to access the field only once. Many implementations allow multiple reads of the same field many times. If you are trying to be implementation independant then it is best to read a column only once. With some drivers, you can call rs.getXXX( i ) until the cows come home(even though it is more efficient and less taxing on DB resources to make the call once)! You should also read the columns in the order that they appear in your query. ex. rs.getString( 1 ) then rs.getString( 2 ) ....
Jamie
[ July 15, 2002: Message edited by: Jamie Robertson ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic