Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Multiple rows into database from jtable

    how to insert multiple rows into a database from a jtable and also retrive the same details from database and show it in a jtable.

    Thanks

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Multiple rows into database from jtable

    By using the query language.

  3. #3
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    thanks for your response but how....

  4. #4
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Multiple rows into database from jtable

    What do you mean how? Search for tutorials.

  5. #5
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    i have but none of them is telling how to do.... i have also tried,but cant figure it out

  6. #6
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Multiple rows into database from jtable

    Show what you have done. Your request is very vague for one to respond.

  7. #7
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    the code i have used have fetched information from the database and show all data row wise perfectly in a jframe but when i am using a jpanel it does not show any data.
    here is code :

    Java Code:
    public class ClientList1 extends javax.swing.JFrame {
        private Vector<Vector<String>> data; //used for data from database
        private Vector<String> header; //used to store data header
        public ClientList1() throws Exception {
             datatotable();
            initComponents();
        }
    protected void datatotable() throws Exception
    {
       
            data=getclienttable();
            header = new Vector<String>(); // use to create columns in jtable 
            header.add("Client Name");
            header.add("City"); 
            header.add("Phone No."); 
            header.add("Total Amount"); 
            header.add("Balance Amount");
            
    }
      public Vector getclienttable()throws Exception // use to fetch information from database
    {
    Vector<Vector<String>> clientVector = new Vector<Vector<String>>();
    
    DBConnect o=new DBConnect();
    ResultSet rs;
    try
    {
        rs=o.queryreturn("SELECT CNAME,CCITY,CPHONE,CTOTAL FROM CLIENTDETAIL");
    
    while(rs.next())
    {
    Vector<String> client = new Vector<String>();
    client.add(rs.getString(1)); 
    client.add(rs.getString(2)); 
    client.add(rs.getString(3)); 
    client.add(rs.getString(4));
    clientVector.add(client);
    }
    }
    catch(Exception ex)
    {}
     return clientVector;
    }
    }

  8. #8
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    it is working perfectle in a jframe but not working in a jpanel.in j panel it does not shows anything even not any error.

  9. #9
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    hello can anyone help?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Multiple rows into database from jtable

    Quote Originally Posted by sharmapiyush View Post
    it is working perfectle in a jframe but not working in a jpanel.in j panel it does not shows anything even not any error.
    That implies the code is different somehow.
    You have only shown us the JFrame based code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    i have used the same code for jpanel also but nothing happens...code is not different

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Multiple rows into database from jtable

    Something's different....and with only the JFrame code in front of us (which apparently works) we are in no position to say what.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    This is the JPanel Coding

    Java Code:
    public class ClientList extends javax.swing.JPanel {
    
        MainForm refToMainForm;
        private Vector<Vector<String>> data; //used for data from database
        private Vector<String> header; //used to store data header
    
        public ClientList(MainForm refToMainForm) throws Exception {
            this.refToMainForm = refToMainForm;
            Imagechanger();
            initComponents();
            datatotable();
        }
     protected void datatotable() throws Exception {
            data = getclienttable();
            header = new Vector<String>();
            header.add("Client Name"); //Empid
            header.add("City"); // employee name
            header.add("Phone No."); // employee position
            header.add("Total Amount"); // employee department
            header.add("Balance Amount");
    
        }
    
        public Vector getclienttable() throws Exception {
            Vector<Vector<String>> clientVector = new Vector<Vector<String>>();
    
            DBConnect o = new DBConnect();
            ResultSet rs;
            try {
                rs = o.queryreturn("SELECT CNAME,CCITY,CPHONE,CTOTAL FROM CLIENTDETAIL");
    
                while (rs.next()) {
                    Vector<String> client = new Vector<String>();
                    client.add(rs.getString(1)); //Empid
                    client.add(rs.getString(2)); //name
                    client.add(rs.getString(3)); //position
                    client.add(rs.getString(4)); //department
                    clientVector.add(client);
                }
            } catch (Exception ex) {
            }
            return clientVector;
        }

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Multiple rows into database from jtable

    And where is the code that actually adds that data to a JTable?

    I mean, your thread title implies that you are having problems moving data from the JTable to the database, but all the code you're showing is simply reading data from the database.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #15
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    class named getclientdata() uses to read data from database and method datatotable() used to present data into a jtable ....

    in customized code option in netbeans i have provided data and header vector to the jtable as arguments.

  16. #16
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    this is the added customized coding..


    Java Code:
    jTable1 = new javax.swing.JTable();
    
    jTable1.setModel(new javax.swing.table.DefaultTableModel(
        data,header
    ));

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Multiple rows into database from jtable

    And the jTable1 is being added to the panel?
    And the panel is being added to the JFrame?

    I still can't tell exactly where you think the problem is.

    You need to narrow it down, because at the moment it could be almost anything.
    Is the table appearing at all, for example?

    Stick some debug statements in your code so you can see what's going on.

    And don't eat exceptions:
    Java Code:
    } catch (Exception ex) {
    }
    You should at least be outputting the stack trace there. Not that I think that's your problem, but it's not a good thing to do.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: Multiple rows into database from jtable

    yes the same,jtable1 is added to panel and panel is added to frame....and the table is also appearing on the panel but blank.

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Multiple rows into database from jtable

    And I assume you are now going to stick some debug in there so you can narrow down what the problem is?
    Should be easy enough to tell whether the code to populate the table is being called or not, and if it is then with what data.
    Similarly with the SQL code.

    This is something you have to work through.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #20
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,870
    Rep Power
    5

    Default Re: Multiple rows into database from jtable

    The snippets really aren't enough. The individual code looks okay to me, the problem is probably in the order in which things happen.

    So I support Tolls' comment: stick System.out.println() debug statements in your different methods to know not only which ones are executed, but also in which order.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Page 1 of 2 12 LastLast

Similar Threads

  1. insert multiple rows
    By tamilram in forum New To Java
    Replies: 1
    Last Post: 03-12-2014, 09:23 AM
  2. Jtable rows
    By riddhishah28 in forum AWT / Swing
    Replies: 3
    Last Post: 02-18-2011, 06:24 AM
  3. How to Add,Remove Rows in JTable
    By Dinesh_rockz in forum AWT / Swing
    Replies: 2
    Last Post: 02-03-2011, 05:30 AM
  4. How to write database queries in Jtable rows and columns?
    By Vignesh Karthick in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2011, 03:55 PM
  5. Remove Jtable rows
    By anilkumar_vist in forum Advanced Java
    Replies: 2
    Last Post: 09-17-2010, 08:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •