Results 1 to 3 of 3
  1. #1
    zenith666 is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Question Using jTable to display query result

    hey guys.

    i'm new here and i'm sorry if this had been posted before. i am trying to display a query result from ms access into a jTable through a search function.

    here is my code:
    Java Code:
    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
    }                                          
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    
       try{
              String woorder = jTextField1.getText();
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:scmdatabase");
              PreparedStatement st=con.prepareStatement("select * from table1 where workorderno = ?");
               st.setString(1, woorder);
               ResultSet rs=st.executeQuery();
    
              while(rs.next()){
                  System.out.println(rs.getString("invoiceno")+" "+rs.getString("invoicedate")+" "+rs.getString("amount"));
              }
           }
           catch(Exception e){
               System.out.println(e);
           }
    the item that i need to display in the jTable is this part:
    Java Code:
    System.out.println(rs.getString("invoiceno")+" "+rs.getString("invoicedate")+" "+rs.getString("amount"));
    really hope that you guys can help me.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,937
    Rep Power
    16

    Default Re: Using jTable to display query result

    Read the API for JTable and follow the link to the Swing tutorial on How to Use Tables.

    Then give it a shot yourself and if you can't get the desired result, post your best efforts with a clear description of where you're stuck, in the form of an SSCCE (Short, Self Contained, Compilable and Executable) example.

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

  3. #3
    zenith666 is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Using jTable to display query result

    thanks darryl,

    i already figured out how to display the result in the jTable.
    my only problem for now is i want to calculate sum of the third column of the jTable. i just can't figured out on how to do it.
    i've tried the getvalueat method, but i don't know how to do the looping of addition and to set the class type.

Similar Threads

  1. Replies: 1
    Last Post: 04-11-2011, 01:39 AM
  2. Replies: 1
    Last Post: 05-20-2010, 07:58 AM
  3. column result query
    By vikashkumar in forum JDBC
    Replies: 0
    Last Post: 04-03-2009, 02:23 PM
  4. Help!! how to turn query result to string
    By stefanybaez in forum Advanced Java
    Replies: 2
    Last Post: 12-11-2008, 11:42 AM
  5. Export query result, procces is to slow
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 06-28-2007, 06:35 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
  •