import java.awt.*;
import javax.swing.*;
import java.sql.*;
class docjtable extends JFrame
{
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
docjtable()throws
Exception
{
setTitle(
"JTable Application" );
setSize(
300, 200 );
setBackground(
Color.gray );
topPanel
= new JPanel();
topPanel.setLayout(
new BorderLayout() );
getContentPane().add(
topPanel );
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con = DriverManager.getConnection("jdbc:odbc:dbAccess","my","asa");
Statement
stmt=con.createStatement();
ResultSet
rs = stmt.executeQuery("Select count(*) from doctor");
rs.next();
int
rows = rs.getInt(1);
rs=stmt.executeQuery("select * from doctor");
ResultSetMetaData rsmd = rs.getMetaData();
int cols =
rsmd.getColumnCount();
String
colNames[] = new String[cols];
for(int
i=1;i<=cols;i++)
colNames[i-1] = rsmd.getColumnName(i);
Object[][] data= new Object[rows][cols];
int i=0,j;
while(rs.next())
{
for(j=1;j<=cols;j++)
data[i][j-1] = rs.getString(j);
i++;
}
table=new JTable(data,colNames);
scrollPane = new JScrollPane( table );
topPanel.add(
scrollPane, BorderLayout.CENTER );
}
public
static void main(String ar[])throws Exception
{
docjtable dj=new docjtable();
dj.setVisible(true);
}
}
thanks
ReplyDeletewrite a menu driven program on student details
ReplyDelete1. adding student details
2. viewing student details
3. deleting student details
4. modify student details
5. show all students
it should have student roll no. , name, marks, average, grades
in java
DeletePost a Comment