Results 1 to 6 of 6
- 11-14-2008, 11:21 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 7
- Rep Power
- 0
error while retrieving data from data base
hi all...
In my one program of java i am reriving data from the MS access database....
my table structure is :
Slno :- Autonumber
Date :-Date/time
Co_no :-number
Acc_name :-text
Tr_type :-text
Amt :-number
and My code is :---
--------------------
Connect c3=new Connect();
ResultSet r3;
r3=c3.stmt.executeQuery("select max(Date) from Transaction");
r3.next();
String temp=r3.getString(2);
System.out.println("temp="+temp);
---------------------------
Connect is class where i hav written the connectio statments and its working fine.
and my error is-----------
java.sql.SQLException: [
icrosoft][ODBC Microsoft Access Driver]Invalid descriptor index
--------------------------------------------------------------
please can you tell me what is the wrong in this...
thank you
- 11-14-2008, 06:35 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
You're only selecting one column, but are attempting to retrieve information from column 2?
What did you expect?
- 11-14-2008, 06:36 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
Change this:
String temp=r3.getString(2);
TO:
String temp=r3.getString(1);
- 11-15-2008, 10:04 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 7
- Rep Power
- 0
Date is my second column only so i am using getString(2);
- 11-15-2008, 10:59 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
Like I said, this
Java Code:r3=c3.stmt.executeQuery("select max(Date) from Transaction");
If "Date" were the second column your query would look something like this
Java Code:r3=c3.stmt.executeQuery("select bogus, max(Date) from Transaction");
If your talking about your table description, then, I hate to break it to you, but it doesn't work that way. The column numbers apply to the columns selected in the query.
- 11-15-2008, 05:10 PM #6
Member
- Join Date
- Nov 2008
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Retrieving data from the DB
By yuchuang in forum JDBCReplies: 2Last Post: 11-27-2007, 09:59 AM -
Problems with Jtable connected to data base
By elizabeth in forum AWT / SwingReplies: 2Last Post: 08-07-2007, 05:24 PM -
Problems when I try to connect to data base
By gabriel in forum JDBCReplies: 1Last Post: 08-06-2007, 06:38 PM -
2 threads sharing a data base connection
By Ed in forum Advanced JavaReplies: 2Last Post: 07-04-2007, 05:41 AM -
Connection to data base
By Daniel in forum JDBCReplies: 2Last Post: 06-07-2007, 05:55 AM
Bookmarks