
i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design the frame... aftr clickg run i need to enter data to ma frame and the data which i enter in my frame should reach mysql and should get saved in a database which we've created in mysql at the beggining itself.... i wanted the coding for such a programme... plz help me...

Hi Friend,
Try this:
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class Retrieve{
public static void main(String[] args){
JFrame f=new JFrame();
JLabel label1=new JLabel("Name: ");
JLabel label2=new JLabel("Address: ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
JButton b=new JButton("Save");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String v1=text1.getText();
String v2=text2.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into data(name,address) values('"+v1+"','"+v2+"')");
JOptionPane.showMessageDialog(null, "Data is inserted successfully");
}
catch(Exception ex){
}
}
});
JPanel p=new JPanel(new GridLayout(3,2));
p.add(label1);
p.add(text1);
p.add(label2);
p.add(text2);
p.add(b);
f.add(p);
f.setVisible(true);
f.pack();
}
}
For NetBeans-Mysql connectivity,
Thanks
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.