2 Replies Latest reply: Mar 20, 2007 11:58 AM by 796447 RSS

    Getting data from a database

    807606
      Hi,
      In my program I have to print some data that I take from a database.

      I have done the following query from the table "data_table":
      insertStr = "select data from data_table where id > 0";
      ResultSet rs = stmt.executeQuery(insertStr);
      How can I get the results of the query?
        • 1. Re: Getting data from a database
          807606
          you really need to read the docs for this, but as a starter: (I'm making up column names etc but you get the idea)
          ...
          String id = rs.getString("id"); // "id" is the column name in the database
          int size = rs.getInt("size");
          // etc
          • 2. Re: Getting data from a database
            796447
            Please look up the documentation of the API:
            http://java.sun.com/j2se/1.5.0/docs/api/index.html

            Find the ResultSet interface in that documentation. Read it.

            Also see the JDBC tutorial:
            http://java.sun.com/docs/books/tutorial/jdbc/index.html