public NewJFrame() { initComponents(); try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin"); } catch(Exception e) { e.printStackTrace(); } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
txtname .setText(""); txtfrom.setText(""); txtgen.setText(""); txtto .setText(""); txttname .setText(""); txtadd.setText(""); txtphone.setText(""); txttrno.setText("");
} private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { { try { st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText(); String k=txtname.getText(); String f=txtgen.getText(); String g=txtadd.getText(); int h=Integer.parseInt(txtphone.getText()); rs=st.executeUpdate("insert into railway values("+a+",'"+b+"','"+c+"','"+d+"','"+e+"','"+f+"','"+g+"',"+h+")"); }
con.close(); st.close(); rs.close(); }
catch(Exception e) { e.printStackTrace(); }
guysss ds s d code for ma project...note that its made by using tools lik textfields , button etc... jbutton1 s d clear button.. and jbutton2 s d savebutton.. if u find any error plz post it fast... ma practical exam starts on 2nd feb.......
Ads