Results 1 to 3 of 3
  1. #1
    asifzbaig is offline Member
    Join Date
    May 2011
    Posts
    56
    Rep Power
    0

    Default How can i get MySQL database table into jTable of my application?

    Hey friends i have tried thid code to get all the data from MySQL table into my GUI jTable:

    ResultSet result = Statement.executeQuery("SELECT * FROM someTable");
    ResultSetMetaData md = result.getMetaData();
    int columnCount = md.getColumnCount();

    Vector columns = new Vector(columnCount);

    //store column names
    for(int i=1; i<=columnCount; i++)
    columns.add(md.getColumnName(i));

    Vector data = new Vector();
    Vector row;

    //store row data
    while(result.next())
    {
    row = new Vector(columnCount);
    for(int i=1; i<=columnCount; i++)
    {
    row.add(result.getString(i));
    }
    data.add(row);
    }

    JTable table = new JTable(data, columns);



    But this gives me a problem that the headings of table is not shown on GUI as it is in database.
    only table with data is showed......can anyone help me pleez??

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    the headings of table is not shown on GUI as it is in database.
    only table with data is showed
    Didn't use a JScrollPane, huh?

    db

Similar Threads

  1. jtable and report from mysql database
    By cisilej in forum NetBeans
    Replies: 0
    Last Post: 02-18-2011, 09:40 AM
  2. adding sum column on jtable that is binded to a database table
    By madcloud in forum Enterprise JavaBeans (EJB)
    Replies: 4
    Last Post: 12-06-2010, 09:26 AM
  3. Replies: 0
    Last Post: 02-21-2010, 12:51 PM
  4. Updating database table from JTable
    By yesjava in forum New To Java
    Replies: 1
    Last Post: 08-16-2008, 11:16 PM
  5. Replies: 0
    Last Post: 03-29-2008, 04:36 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
  •