• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

get a result from the tbll_savings records and tbl_profile

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 DefaultTableModel model = (DefaultTableModel) tbl_rec.getModel();
        Object[] row = new Object[3];
       try {
           String query = "SELECT * FROM tbl_savings";
           pst = conn.prepareStatement(query);
           rs = pst.executeQuery();
           
           while(rs.next()){
               String lnm = rs.getString("Lastname");
               String fnm = rs.getString("Firstname");
               String mnm = rs.getString("Middlename");
           
               String sql = "SELECT * FROM tbl_profile WHERE Lastname <> '"+lnm+"' AND Firstname  <> '"+fnm+"' AND Middlename  <> '"+mnm+"'";
           pst = conn.prepareStatement(sql);
           rs2 = pst.executeQuery();
           while(rs2.next()){
             JOptionPane.showMessageDialog(null, rs2.getString("Lastname"));
           }}
       } catch (Exception e) {
           JOptionPane.showMessageDialog(null, e);
       }
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why are you using option panes for standard output rather than System.out and System.err?
Why are you running two queries inside each other? Why are you using <>?  You didn't ask a question; what is going wrong? Are you getting too many outputs?
Why are you matching names from one table to another? Don't you have a PK in one table and an FK in the other?
 
guillier gutoman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using option pane just to see the result of my query. I use the first query to get the record from that table then after i get the result i want to use the lastname firstname and middlename to the second query's condition. I use 'not equal' to get the names that dont match the same records between two tables. Those fieldnames are foreign keys.
 
guillier gutoman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the results of two queries are shown in the option pane. i just want to get the result of the second query.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the late post; I've been on vacation.

The way people usually do something like this is with an SQL JOIN.  What is the relationship between the tables?  Do they have foreign keys that can key them together?
 
reply
    Bookmark Topic Watch Topic
  • New Topic