This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 62223
193
  • 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.
 
Marshal
Posts: 5632
147
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?
 
I do some of my very best work in water. Like this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!