Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. int adm_no = Integer.parseInt(jTextField1.getText());
  2. String name = jTextField2.getText();
  3. String stream = jTextField3.getText();
  4. if (name.isEmpty())
  5. {
  6. JOptionPane.showMessageDialog(this, "ERROR");
  7. }
  8. else if (stream.isEmpty())
  9. {
  10. JOptionPane.showMessageDialog(this, "ERROR");
  11. }
  12. else
  13. {
  14. try
  15. {
  16. Class.forName("java.sql.DriverManager");
  17. Connection con = (Connection)
  18. DriverManager.getConnection("jdbc:mysql://localhost:3306/student" , "root" , "tiger");
  19. Statement stmt = (Statement) con.createStatement();
  20. String query = "Insert into student values ("+adm_no+" , '"+name+"' , '"+stream+"');";
  21. stmt.executeUpdate(query);
  22. }
  23. catch(Exception e)
  24. {
  25. JOptionPane.showMessageDialog(this, e);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement