hi.. to all..
i executed the following program.. i entered the data in the output screen..but the data is not updated in the database.... Is there any problem with the program.. plz help me........
i executed the following program.. i entered the data in the output screen..but the data is not updated in the database.... Is there any problem with the program.. plz help me........
Code:
import java.applet.*; import java.awt.*; import java.sql.*; import java.awt.event.*; import sun.jdbc.odbc.*; public class Customerdetails extends Frame implements ActionListener { TextField ccod,cname,add,phno,conp,email,fax; Label l1,l2,l3,l4,l5,l6,l7; Button save,exit; Connection con; ResultSet rs; Statement stmt; String s1,s2,s3,s4,s5,s6,s7; public Customerdetails() { super("CustomerDetails"); setSize(700,750); setLayout(null); setBackground(new java.awt.Color(245, 117, 105)); l1=new Label("Customercode"); l2=new Label("CompanyName"); l3=new Label("Address"); l4=new Label("PhoneNumber"); l5=new Label("Contact person"); l6=new Label("EmailAddress"); l7=new Label("FaxNumber"); l1.setBounds(20,100,100,70); l2.setBounds(20,160,100,70); l3.setBounds(20,220,100,70); l4.setBounds(20,280,100,70); l5.setBounds(20,340,100,70); l6.setBounds(20,400,100,70); l7.setBounds(20,460,100,70); ccod=new TextField(); cname=new TextField(); add=new TextField(); phno=new TextField(); conp=new TextField(); email=new TextField(); fax=new TextField(); ccod.setBounds(200,120,150,40); cname.setBounds(200,180,150,40); add.setBounds(200,240,150,40); phno.setBounds(200,300,150,40); conp.setBounds(200,360,150,40); email.setBounds(200,420,150,40); fax.setBounds(200,480,150,40); Button save= new Button("Save"); Button exit= new Button("Exit"); save.setBounds(160,580,100,40); exit.setBounds(280,580,100,40); add(l1); add(ccod); add(l2); add(cname); add(l3); add(add); add(l4); add(phno); add(l5); add(conp); add(l6); add(email); add(l7); add(fax); add(save); add(exit); save.addActionListener(this); exit.addActionListener(this); setVisible(true); addWindowListener(new WindowAdapter(){ public void WindowClosing(WindowEvent w) {System.exit(0);}}); } public void actionPerformed(ActionEvent ae) { Customerdetails cud= new Customerdetails(); if(ae.getSource()==save) { s1=ccod.getText(); s2=cname.getText(); s3=add.getText(); s4=phno.getText(); s5=conp.getText(); s6=email.getText(); s7=fax.getText(); try { String query = "insert into Customerdetails (Customercode,CompanyName,Address,PhoneNumber,Contact person,EmailAddress,FaxNumber)"+ "values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"','"+s7+"')"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:prism"); stmt=con.createStatement(); rs=stmt.executeQuery(query); stmt.close(); } catch(ClassNotFoundException e) { System.out.println(e); } catch(SQLException e) { System.out.println(e); } } else if(ae.getSource()==exit) { System.exit(0); } else { System.exit(0); } } public static void main(String args[]) { Customerdetails cud= new Customerdetails(); } }
Comment