Guest User

java mysql connectivity

a guest
Apr 24th, 2018
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1.  
  2. private void jinsertActionPerformed(java.awt.event.ActionEvent evt) {
  3. try {
  4. String id=jid.getText();
  5. String name=jname.getText();
  6. String addr=jaddr.getText();
  7.  
  8.  
  9. Class.forName("com.mysql.jdbc.Driver");// TODO add your handling code here:
  10. try {
  11. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/b1","root","root");
  12.  
  13. Statement stmt=con.createStatement();
  14. String q="insert into t1(id,name,addr) values("+id+",'"+name+"','"+addr+"');";
  15. stmt.executeUpdate(q);
  16. JOptionPane.showMessageDialog(null, "Data inserted");
  17. } catch (SQLException ex) {
  18. Logger.getLogger(sqlf.class.getName()).log(Level.SEVERE, null, ex);
  19. }
  20.  
  21.  
  22. } catch (ClassNotFoundException ex) {
  23. Logger.getLogger(sqlf.class.getName()).log(Level.SEVERE, null, ex);
  24. }
  25. }
Add Comment
Please, Sign In to add comment