getting data from MySQL in Jtable

Hi,

Does anyone know how to get "table names" and their "field names" from MySQL in the Jtable?

I've done the coding for retreiveing table names and their attributes from my database , the problem is i don't know how to put them in Jtable! Here is the part of code which returns theTable names and their field names:

Statement tableStatement = conn.createStatement();

Statement fieldStatement = conn.createStatement();

ResultSet fields = null;

ResultSet tables = tableStatement.executeQuery("show tables");

while(tables.next())

{

String tableName = tables.getString(1);

System.out.println("table name::" + tableName);

fields = fieldStatement.executeQuery("describe " + tableName);

while(fields.next())

{

String fieldName = fields.getString(1);

System.out.println("\tfieldName::" + fieldName);

}

I'd be very grateful if you could help me with doing this.

Elham

[977 byte] By [Eliiia] at [2007-11-26 21:14:02]
# 1

It sounds like you got the retrieving them from the database part.

I would suggest you work on create a simple table first:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

Once you have an understanding of how a jTable works, then try to connect the table name portion to it.

Also, I would highly recommend that you keep any GUI code that you write separate from your JDBC code.

zadoka at 2007-7-10 2:52:21 > top of Java-index,Desktop,Developing for the Desktop...
# 2
I can extract any table field name using this:ResultSet res = conn.executeQuery(DESCRIBE mytable);res.next();String field_name = res.getString(1);maybe..to know tables just use "SHOW TABLES;" in the SQL, but i do not yet test this.using mySQL 5.0
shadowdancera at 2007-7-10 2:52:21 > top of Java-index,Desktop,Developing for the Desktop...