
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();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
full red line s coming guys..... can smone help me in removing errors from ds...........

Hi Friend,
Why are you using private void jButton2ActionPerformed?
If you want to perform any action on button then use the following code:
Suppose, you have created an object (button) of JButton class then use the following:
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//--------here you can use your insert query------
}
});
Thanks

actually m making programmes with tools lik button,textfield etc.. and ds line "private void jButton2ActionPerformed" automatically comes in the programme when i double click d second button which i,ve added in ma frame....
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.