if(e.getSource()==b5) { ta.setText(str); try { con=d.getConnect(); PreparedStatement pst=con.prepareStatement("select * from test"); ResultSet rs=pst.executeQuery(); while(rs.next()) { int n1=rs.getInt(1); String n2=rs.getString(2); String n=rs.getString(3); double n3=rs.getDouble(4); String n4=rs.getString(5); /*append all values to the text area by ta.append()*/ ta.append(""+n1+"\t"+n2+"\t"+n+"\t"+n3+"\t"+n4+"\n"); //JOptionPane.showMessageDialog(null,n1+"\n"+n2+"\n"+n3+"\n"+n4); l5.setText("View test Table Data"); } }catch(Exception ae){ ae.printStackTrace(); } }//Button b5 if if(e.getSource()==b2) { ta.setText(str); int sno=Integer.parseInt(t1.getText()); try { con=d.getConnect(); PreparedStatement pst=con.prepareStatement("delete from test where Empnumber="+sno); int i=pst.executeUpdate(); if(i>0) l5.setText("Deletion Operation Performed"); else l5.setText("Deletion Operation Failed"); pst.clearParameters(); t1.setText(""); t2.setText(""); t.setText(""); t3.setText(""); t4.setText(""); }catch(Exception ae){ ae.printStackTrace(); } }//Button b2 if if(e.getSource()==b3) { ta.setText(str); int sno=Integer.parseInt(t1.getText()); String sname=t2.getText(); String spwd=t.getText(); double sal=Double.parseDouble(t3.getText()); String address=t4.getText(); try { con=d.getConnect(); //PreparedStatement pst=con.prepareStatement("update test set sname=?,spwd=?,sal=?,address=? where sno=?"); PreparedStatement pst=con.prepareStatement("update test set Empname=?,Emppassword=?,Empsal=?,Empadd=? where Empnumber=?"); pst.setString(1,sname); pst.setString(2,spwd); pst.setDouble(3,sal); pst.setString(4,address); pst.setInt(5,sno); int i=pst.executeUpdate(); if(i>0) l5.setText("Update Operation Performed"); else l5.setText("Update Operation Failed"); pst.clearParameters(); t1.setText(""); t2.setText(""); t.setText(""); t3.setText(""); t4.setText(""); }catch(Exception ae){ ae.printStackTrace(); } }//button b3 if if(e.getSource()==b4) { ta.setText(str); int sno=Integer.parseInt(t1.getText()); try { con=d.getConnect(); PreparedStatement pst=con.prepareStatement("select * from test where Empnumber="+sno); ResultSet rs=pst.executeQuery(); if(rs.next()) { t1.setText(""+rs.getInt(1)); t2.setText(rs.getString(2)); t.setText(rs.getString(3)); t3.setText(""+rs.getDouble(4)); t4.setText(rs.getString(5)); ta.append(t1.getText()+"\n"+t2.getText()+"\n"+t.getText()+"\n"+t3.getText()+"\n"+t4.getText()); l5.setText("Record Avilable with Serial Number : "+sno); } else { l5.setText("No Record Avilable with Serial Number : "+sno); pst.clearParameters(); t1.setText(""); t2.setText(""); t.setText(""); t3.setText(""); t4.setText(""); } }catch(Exception ae){ ae.printStackTrace(); } }//Button b5 if if(e.getSource()==exit) System.exit(0);
} } class Database { public static void main(String[] args) { D1 d=new D1(); }
}
in this code the o/p is coming properly. My problem is when we click on "reports" button the seprate frame(window) is coming , but the window is size is very very small . I want that a medium screen and the mattter inside the frame is middle the new window
pls help me.
View Answers
July 23, 2010 at 11:21 AM
Hi Friend,
Try the following code:
if(e.getSource()==b){ int sno=Integer.parseInt(t1.getText()); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:access"); PreparedStatement pst=con.prepareStatement("select * from test where Empnumber="+sno); ResultSet rs=pst.executeQuery(); JFrame f=new JFrame(); f.getContentPane().setLayout(null); int n1=0,n3=0; String n="",n2="",n4="";