• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

get a result from the tbll_savings records and tbl_profile  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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: 63790
209
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 5795
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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?
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!