Results 1 to 4 of 4

Thread: How to Extract records from Mysql database using JTable

  1. #1
    Join Date
    Feb 2009
    Posts
    105

    How to Extract records from Mysql database using JTable

    I have MySQL 5.0 installed on my computer. I am trying to retrieve information from my MySQL Database and inserting it into a JTable displaying multiple rows. However I am able to retrieving the information from the JTable but is only displaying the last record in the database no matter how many records are in the database.I want to display all the records from the database, i have tried out lot of alternative but nothing works.

    please help..

  2. #2
    Join Date
    Apr 2008
    Posts
    193

    Re: How to Extract records from Mysql database using JTable

    Create a Java Application Project. From main menu File -> New Projects. Choose Java category, and Java Application.

    Now delete the Main.java file under Source Packages. This file was automatically created by the wizard for you. Add a new JFrame Form . Right Click Project node -> New -> JFrame Form.


    Drag and Drop JTable from the palette on to the designer.

    Now Drag and drop the database Table on to the JTable in the designer. To do this, go to the Services tab , and expand the Databases -> Your MySQL database node -> Table, and select the table you want to bind to the JTable. Drag and drop it on to the JTable on the designer.

    Make sure the MySQL driver jar file is under the libraries node of the project. Build and Run the project. when running the project it will ask you to select the main class. This is because we deleted the main class earlier, and we now need to provide the main class to begin execution. Select the default.

    You would see all the records imported into the JTable.

  3. #3
    Join Date
    Dec 2008
    Posts
    161

    Re: How to Extract records from Mysql database using JTable

    Use the following code to extract records from the MYsql database..

    Code:
    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);

  4. #4
    Join Date
    Dec 2008
    Posts
    202

    Re: How to Extract records from Mysql database using JTable

    I'm trying to populate a JTable with data from an online MySQL database. Here's what I've done so far:

    1) Add the table to the form
    2) Right click on table, select Table Contents, select bound, Import data to form (the connection works and the respective table can be viewed in the services window)
    3) Right click on table again, select Bind, select Elements, shift Available to Selected.

Similar Threads

  1. Importing large quantities of records in MySQL DB
    By Allison in forum Software Development
    Replies: 3
    Last Post: 03-12-2010, 04:24 AM
  2. Replies: 3
    Last Post: 19-07-2010, 04:23 PM
  3. PHP mysql select unique records from one table
    By Captain Carrot in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 12:18 PM
  4. MySql to show records which is not a value
    By Grundy in forum Software Development
    Replies: 3
    Last Post: 23-07-2009, 07:48 PM
  5. How to Extract Particular Records from the Database?
    By Sukhvinder in forum Software Development
    Replies: 2
    Last Post: 26-01-2009, 06:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,383,353.22037 seconds with 16 queries