Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. try{
  2. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sampledata","root","");
  3. String sql= "SELECT * FROM studentinfo";
  4. pst=con.prepareStatement(sql);
  5. rs=pst.executeQuery();
  6. jTable1.setModel(DbUtils.resultSetToTableModel(rs));
  7. }
  8. catch(Exception ex){
  9. JOptionPane.showMessageDialog(null, ex);
  10. }
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. try {
  18. // TODO add your handling code here:
  19. String sql = "INSERT INTO studentinfo" + "(FIRSTNAME, LASTNAME, GRADELEVEL, SECTION, CN)" + "VALUES (?,?,?,?,?)";
  20. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sampledata","root","");
  21. pst = con.prepareStatement (sql);
  22. pst.setString(1, textfn.getText());
  23. pst.setString(2, textln.getText());
  24. pst.setString(3, textgl.getText());
  25. pst.setString(4, textsection.getText());
  26. pst.setString(5, textcn.getText());
  27. pst.executeUpdate();
  28. JOptionPane.showMessageDialog(this, "Added Successfully");
  29. } catch (SQLException ex) {
  30. Logger.getLogger(StudentRegistry.class.getName()).log(Level.SEVERE, null, ex);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement