In this tutorial will teach jdbc record insertion into mysql database step by step.
Connection con;
PreparedStatement pst;
public void Connect()
{
try {
Class.forName("com.mysql.jdbc.Driver"); //Register the mysql driver
con = DriverManager.getConnection("jdbc:mysql://localhost/phonebook","root","");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
} try
{
String friendname,phone,place;
friendname = txtFname.getText();
phone = txtphone.getText();
place = txtplace.getText();
pst = con.prepareStatement("insert into records(fname,phone,place)values(?,?,?)");
pst.setString(1,friendname);
pst.setString(2,phone);
pst.setString(3,place);
int status = pst.executeUpdate();
if(status==1)
{
JOptionPane.showMessageDialog(this, "Record Saved");
txtFname.setText("");
txtphone.setText("");
txtplace.setText("");
txtFname.requestFocus();
}
else
{
JOptionPane.showMessageDialog(this, "Record Failed");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
What Is the Tesla Pi Phone? Imagine if Tesla, the company that makes famous…
Inventory Management POS systems are now an essential part of modern businesses such as bookshops,…
If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…
GitHub is a powerful tool used by teams and developers around the globe. This guide is…
It's like having a super-smart buddy that is always there to help you write stories,…
The UK is known for its rich history, diverse culture, and most of all its…