The following is a pgm to display a jatable when we click on the "search" button.But this pgm didn't work.It didn't show any error.If anyone know the answer,plz help me.I'm using MsAccess as back end.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class Frm extends JFrame implements ActionListener
{
Container con;
Statement st;
ResultSet rs,rs1;
Connection cn;
JTable tab;
JScrollPane jsp;
ResultSetMetaData rm;
String rw[][];
String[] cl;
JTextField t0,t1,t2,t3,t4,t5;
PreparedStatement ps;
JLabel l0,l1,l2,l3,l4,l5;
JButton b0,b1,b2,b3,b4,b5,b6;
public Frm(String z)
{
super(z);
con=getContentPane();
con.setLayout(new BorderLayout());
t0=new JTextField(15);
t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
t5=new JTextField(15);
l0=new JLabel("Company's Item code");
l1=new JLabel("Item Name");
l2=new JLabel("Price");
l3=new JLabel("Tax");
l4=new JLabel("Brand");
l5=new JLabel("Supplier");
b0=new JButton("Search");
b2=new JButton("Update");
b4=new JButton("Clear");
b5=new JButton("Close");
con.setLayout(null);
l0.setBounds(200,50,100,30);
t0.setBounds(310,50,100,20);
l1.setBounds(200,100,100,30);
t1.setBounds(310,100,100,20);
l2.setBounds(200,150,100,30);
t2.setBounds(310,150,100,20);
l3.setBounds(200,200,100,30);
t3.setBounds(310,200,100,20);
l4.setBounds(200,250,100,30);
t4.setBounds(310,250,100,20);
l5.setBounds(200,300,100,30);
t5.setBounds(310,300,100,20);
b0.setBounds(210,400,100,30);
con.add(l0);
con. add(t0);
con.add(l1);
con.add(t1);
con.add(l2);
con.add(t2);
con.add(l3);
con.add(t3);
con.add(l4);
con.add(t4);
con.add(l5);
con.add(t5);
con.add(b0);
b0.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b0)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:Trading");
st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String s="select * from tbl_ITEM";
rs=st.executeQuery(s);
rm=rs.getMetaData();
int n=rm.getColumnCount();
cl=new String[n];
for(int i=0;i
{
cl[i]=rm.getColumnName(i+1);
}
int count=0,i=0,j;
while(rs.next())
{
count++;
}
rs.first();
rw=new String[count][n];
do
{
j=0;
for(int k=1;k<=n;k++)
{
rw[i][j]=rs.getString(k);
j++;
}
i++;
}
while(rs.next());
}
catch(Exception e)
{
System.out.println("Error Catch"+e);
}
tab=new JTable(rw,cl);
jsp=new JScrollPane(tab,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
con.add(jsp,BorderLayout.CENTER);
}
}
}
public class Temp0
{
public static void main(String a[])
{
Frm f1=new Frm("Details");
f1.setSize(800,800);
f1.setVisible(true);
}
}
2007-02-21
00:47:00
·
1 answers
·
asked by
Appu s
1