This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in extracting values from ResultSet

 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
Piyush Daiya
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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 ]
 
Alex Sanchez
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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).
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic