Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-04-2009
Member
 
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..
Reply With Quote
  #2  
Old 08-04-2009
Member
 
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.
Reply With Quote
  #3  
Old 08-04-2009
Member
 
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);
Reply With Quote
  #4  
Old 08-04-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Extract records from Mysql database using JTable"
Thread Thread Starter Forum Replies Last Post
Importing large quantities of records in MySQL DB Allison Software Development 3 03-12-2010 04:24 AM
PHP - I want to retrieve records from specific field from a MySQL table and build array using PHP bond007dev Software Development 3 19-07-2010 04:23 PM
PHP mysql select unique records from one table Captain Carrot Software Development 6 13-05-2010 12:18 PM
MySql to show records which is not a value Grundy Software Development 3 23-07-2009 07:48 PM
How to Extract Particular Records from the Database? Sukhvinder Software Development 2 26-01-2009 06:28 PM


All times are GMT +5.5. The time now is 11:15 AM.