Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Reading the columns, JDBC

  • 10-03-2009 9:11pm
    #1
    Registered Users, Registered Users 2 Posts: 539 ✭✭✭


    So i have this peace of java code

    try {
    Dao d = new Dao();
    Connection con = d.getConnection();
    Statement s = con.createStatement();
    s.execute("select ID from VEHICLES"); // select the data from the table

    ResultSet rs = s.getResultSet(); // get any ResultSet that came from our quer
    if (rs != null) // if rs == null, then there is no ResultSet to view
    {
    while (rs.next()) // this will step through our data row-by-row
    {
    /* the next line will get the first column in our current row's ResultSet
    as a String ( getString( columnNumber) ) and output it to the screen */
    result.add(rs.getString(1));
    }
    }

    s.close(); // close the Statement to let the database know we're done with it
    con.close(); // close the Connection to let the database know we're done with it

    } catch (Exception ex) {
    System.out.println("Message " + ex.getMessage());
    }

    It reads all rows in a database. I would be searcing some particular Vehicle lets say. What I want to know is, how would I extract the corresponding columns to the row I find.

    Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 539 ✭✭✭but43r


    Ok firgured this one out.
    Instead of having s.execute("select ID from VEHICLES"); i had to have s.execute("select * from VEHICLES"); and just change result.add(rs.getString(1)) whichever column I want :)


  • Registered Users, Registered Users 2 Posts: 25 Malached


    SELECT id FROM vehicles where <vehicle_type> = <vehicle type> basic ANSI SQL. Any language.


Advertisement