Results 1 to 3 of 3
  1. #1
    marvelk is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default retrivieving from oraclexe database table to data program

    i try to retrieve data from a database to my java program but the code doesn't seem to work no error but it just doesnt work

    here is the code
    try {
    String nam = jComboBox9.getSelectedItem().toString();

    st2 = con.createStatement();

    rs1 = st2.executeQuery("select * from member2 where name = "+ nam +" " );

    rs1.next();

    jComboBox9.addItem(rs1.getString(1));
    jTextArea3.setText(rs1.getString(2));
    jComboBox10.setSelectedItem(rs1.getString(3));
    jComboBox11.setSelectedItem(rs1.getString(4));
    jTextField20.setText(rs1.getString(5));
    jTextField21.setText(rs1.getString(6));


    } catch (SQLException ex) {
    Logger.getLogger(CPM.class.getName()).log(Level.SE VERE, null, ex);
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by marvelk View Post
    rs1 = st2.executeQuery("select * from member2 where name = "+ nam +" " );
    For starters, shouldn't a value be put in single quotes? having said that, it reminds me of this.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,953
    Rep Power
    19

    Default

    Debug it.
    Print out the values.

    As Jos says, I doubt that SQL will run so you ought to be getting an exception. Where it's going (are you logging to a file?) I have no idea.

    ETA: Oh yes, and this is one of the reasons for keeping display logic separate from db logic.
    Make a DAO (Data Access Object) that gets the data you want from the db and creates a List of a suitable class which it returns.
    The display can then show the data based on this list and not care where it comes from.
    In addition you'll be able to test the db logic in isolation since it won't care what's done with that data.

    Oh...and PreparedStatement.
    Last edited by Tolls; 02-03-2011 at 08:25 AM.

Similar Threads

  1. error in reading data from table in pidgree database
    By chethan_kc in forum Java Servlet
    Replies: 17
    Last Post: 02-18-2011, 02:11 PM
  2. Connecting to a database table
    By kiz106 in forum JDBC
    Replies: 1
    Last Post: 05-19-2010, 10:33 AM
  3. How to display database in table
    By tamnc in forum SWT / JFace
    Replies: 0
    Last Post: 03-15-2010, 05:57 AM
  4. Replies: 0
    Last Post: 02-09-2008, 08:22 PM
  5. Replies: 1
    Last Post: 02-01-2008, 01:21 PM

Posting Permissions

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