Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String name= jTextField1.getText();
- String mobile= jTextField2.getText();
- String email= jTextField3.getText();
- if (name.isEmpty())
- JOptionPane.showMessageDialog(null,"Please enter your name");
- else if (mobile.isEmpty())
- JOptionPane.showMessageDialog(null,"Please enter your mobile");
- else if (email.isEmpty())
- JOptionPane.showMessageDialog(null,"Please enter your email");
- else {
- try {
- Class.forName("java.sql.DriverManager");
- Connection con = (Connection) DriverManager.getConnection ("jdbc:mysql://localhost:3306/practicals", "root", "system");
- Statement stmt = (Statement) con.createStatement();
- String query="insert into contacts values ('"+name+"','"+mobile+"','"+email+"');";
- stmt.executeUpdate(query);
- JOptionPane.showMessageDialog(this, "Added Successfully");
- } catch (Exception e)
- {
- JOptionPane.showMessageDialog(null,e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment