
i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent

import java.io.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
class JTableDatabase extends JFrame{
ResultSet rs;
JTableDatabase(){
final Vector columnNames = new Vector();
final Vector data = new Vector();
JPanel panel=new JPanel();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = con.createStatement();
ResultSet rs= st.executeQuery("Select * from employee");
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for(int i = 1; i <= columns; i++){
columnNames.addElement(md.getColumnName(i));
}
while(rs.next()){
Vector row = new Vector(columns);
for(int i = 1; i <= columns; i++){
row.addElement(rs.getObject(i));
}
data.addElement(row);
}
}
catch(Exception e){}
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
add(panel);
}
public static void main(String arg[]){
try{
JTableDatabase frame=new JTableDatabase();
frame.setSize(550,200);
frame.setVisible(true);
}
catch(Exception e)
{}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.