Respected sir there is a problem in this code when i add any new record in ms access data base from my code, it gives only null pointer error sir please help me my code are given below compilatation class name is "jd".
import java.io.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.sql.*; import java.lang.String.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; class menu extends Frame implements ActionListener { Font m=new Font("monotype corsiva",Font.BOLD+Font.ITALIC,50); Font m1=new Font("scriptmtbold",Font.BOLD+Font.ITALIC,40); Font m2=new Font("scriptmtbold",Font.BOLD,20); Frame f; Label l1, l2,l3,l4,l5,l6,l7,l8,l9,l10; Panel p; Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10; public menu() { super("INDANE - SHANTI GAS AGENCY"); int a=getWidth(); int b=getHeight(); setSize(a,b); setBackground(Color.green); setForeground(Color.blue); p =new Panel(); setVisible(true); p.setSize(400,300); p.setBackground(Color.red); setLayout(null); l1=new Label("SHANTI GAS SERVICE"); l2=new Label("We Gives 18 Hours Service"); l3=new Label("Customer Care Application."); l4=new Label("Add New Customer"); l5=new Label("Display Customer Record"); l6=new Label("Delete Cuctomer Record"); l7=new Label("Update Customer Record"); l8=new Label("Inquiary"); l9=new Label("Center Facility"); l10=new Label("We are happy to help you"); b4=new Button("ADD"); b5=new Button("Display"); b6=new Button("Delete Record"); b7=new Button("Update"); b8=new Button("Query"); b9=new Button("Facility List"); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); b7.addActionListener(this); b8.addActionListener(this); b9.addActionListener(this); b4.setBounds(500,260,100,30); b5.setBounds(500,300,100,30); b6.setBounds(500,340,100,30); b7.setBounds(500,380,100,30); b8.setBounds(500,420,100,30); b9.setBounds(500,460,100,30); p.setBounds(a/20,b/20,700,70); l1.setFont(m); l2.setFont(m1); l3.setFont(m2); l4.setFont(m2); l5.setFont(m2); l6.setFont(m2); l7.setFont(m2); l8.setFont(m2); l9.setFont(m2); l10.setFont(m); p.setBounds(50,50,700,80); l2.setBounds(90,150,550,30); l3.setBounds(90,190,550,30); l4.setBounds(150,260,550,30); l5.setBounds(150,300,550,30); l6.setBounds(150,340,550,30); l7.setBounds(150,380,550,30); l8.setBounds(150,420,550,30); l9.setBounds(150,460,550,30); l10.setBounds(250,550,600,50); p.add(l1); add(b4); add(b5); add(b6); add(b7); add(b8); add(b9); add(p); add(l2); add(l3); add(l4); add(l5); add(l6); add(l7); add(l8); add(l9); add(l10); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } public void processWindowEvent(WindowEvent w) { if(w.getID()==WindowEvent.WINDOW_CLOSING) { dispose(); System.exit(0); } } public void actionPerformed(ActionEvent e) { if (e.getSource()==b4) { addform f1=new addform(); f1.setVisible(true); } } } class addform extends Frame implements ActionListener { Font m=new Font("monotype corsiva",Font.BOLD+Font.ITALIC,50); Font m1=new Font("scriptmtbold",Font.BOLD+Font.ITALIC,30); Font m2=new Font("scriptmtbold",Font.BOLD,25); Font m3=new Font("scriptmtbold",Font.BOLD,18); TextField t1,t2,t3,t4,t5,t6,t7,t8,t9; Choice c1,c2,c3,c4; Button b1; Frame f; Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10; Panel p; public addform() { super("INDANE - SHANTI GAS AGENCY"); setSize(950,950); int a=getWidth(); int b=getHeight(); setSize(a,b); setVisible(true); setBackground(Color.green); setForeground(Color.blue); p=new Panel(); setLayout(null); l1=new Label("Customer Detail Form"); l2=new Label("Customer Name"); l3=new Label("Father Name"); l4=new Label("HouseNo"); l5=new Label("Locality"); l6=new Label("City"); l7=new Label("State"); l8=new Label("Unit in Family"); l9=new Label("Cylendor Unit"); l10=new Label("Customer Code"); t1=new TextField(50); t2=new TextField(50); t3=new TextField(30); t4=new TextField(30); t5=new TextField(10); c1=new Choice(); c2=new Choice(); c3=new Choice(); c4=new Choice(); c1.add("kanpur"); c1.add("Lucknow"); c1.add("Mumbai"); c2.add("Uttar Pradesh"); c2.add("Madhya Pradesh"); c3.add("1"); c3.add("2"); c3.add("3"); c4.add("Single"); c4.add("Double"); c4.add("Triple"); l1.setFont(m); l2.setFont(m3); l3.setFont(m3); l4.setFont(m3); l5.setFont(m3); l6.setFont(m3); l7.setFont(m3); l8.setFont(m3); l9.setFont(m3); l10.setFont(m3); b1=new Button("ADD RECORD"); b1.addActionListener(this); p.setBounds(a/20,b/20,550,70); l2.setBounds(50,200,150,20); l3.setBounds(50,250,150,20); l4.setBounds(50,300,150,20); l5.setBounds(50,350,150,20); l6.setBounds(50,400,150,20); l7.setBounds(50,450,150,20); l8.setBounds(50,500,150,20); l9.setBounds(50,550,150,20); l10.setBounds(50,600,160,20); t1.setBounds(400,200,250,25); t2.setBounds(400,250,250,25); t3.setBounds(400,300,250,25); t4.setBounds(400,350,250,25); t5.setBounds(400,600,250,25); b1.setBounds(300,700,250,25); c1.setBounds(400,400,200,25); c2.setBounds(400,450,200,25); c3.setBounds(400,500,200,25); c4.setBounds(400,550,200,25); p.setBackground(Color.red); p.add(l1); add(p); add(l2); add(l3); add(l4); add(l5); add(l6); add(l7); add(l8); add(l9); add(l10); add(t1); add(t2); add(t3); add(t4); add(t5); add(b1); add(c1); add(c2); add(c3); add(c4); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } public void processWindowEvent(WindowEvent w) { if(w.getID()==WindowEvent.WINDOW_CLOSING) { dispose(); } } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { try{ String nm,fnm,loclt,ct,st,cu; int hn,uf,cc; nm=new String(t1.getText()); fnm=new String(t2.getText()); hn= Integer.parseInt(t3.getText()); loclt=new String(t4.getText()); ct=new String(t5.getText()); st=new String(t6.getText()); uf=Integer.parseInt(t7.getText()); cu=new String(t8.getText()); cc= Integer.parseInt(t9.getText()); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection("jdbc:odbc:project"); PreparedStatement stmt=cn.prepareStatement("insert into customerrecord values(?,?,?,?,?,?,?,?,?)"); stmt.setString(1,nm); stmt.setString(2,fnm); stmt.setInt(3,hn); stmt.setString(4,loclt); stmt.setString(5,ct); stmt.setString(6,st); stmt.setInt(7,uf); stmt.setString(8,cu); stmt.setInt(9,cc); int rs=stmt.executeUpdate(); //cn.commit(); cn.close(); } catch(SQLException c) {} catch(Exception c) { System.out.println("error" +c); } } } } class jd { public static void main(String args[]) { menu m=new menu(); } }
Ads