Results 1 to 6 of 6
  1. #1
    kirtesh4u is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default 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

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    You're only selecting one column, but are attempting to retrieve information from column 2?

    What did you expect?

  3. #3
    losintikfos is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    Change this:
    String temp=r3.getString(2);

    TO:
    String temp=r3.getString(1);

  4. #4
    kirtesh4u is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default

    Date is my second column only so i am using getString(2);

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Like I said, this
    Java Code:
    r3=c3.stmt.executeQuery("select max(Date) from Transaction");
    is only selecting one column, so how is Date the second column?

    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");
    So once again, what did you expect? How did you figure that "Date" was the second column when you're only selecting one?

    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.

  6. #6
    kirtesh4u is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Retrieving data from the DB
    By yuchuang in forum JDBC
    Replies: 2
    Last Post: 11-27-2007, 09:59 AM
  2. Problems with Jtable connected to data base
    By elizabeth in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2007, 04:24 PM
  3. Replies: 1
    Last Post: 08-06-2007, 05:38 PM
  4. 2 threads sharing a data base connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 04:41 AM
  5. Connection to data base
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 06-07-2007, 04:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •