Win a copy of Learning Regular Expressions this week in the General Computing 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • 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: 60192
188
  • 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: 5135
138
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?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!