



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/susms","root",""); Statement std = (Statement) con.createStatement(); String qry ="insert into Students values ('" + txtID.getText() + "','" + txtName.getText() + "','" + cboGender.getSelectedItem() + "','" + txtAddress.getText() + "','" + txtPhone.getText() + "')"; int x = std.executeUpdate(qry); if (x==1) { JOptionPane.showMessageDialog(null, "insert suceesfully"); Filldata(); } else {
JOptionPane.showMessageDialog(null, "inset Failled"); } } catch (Exception e) { JOptionPane.showMessageDialog(this, e); } FILL JTABLE CODE try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/susms","root",""); Statement std = (Statement) con.createStatement(); String qry ="select * from Students "; Statement pst = (Statement) con.prepareStatement(qry); ResultSet rs; rs=pst.executeQuery(qry); jTable1.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(this, e); }
txtAddress.setText(add4); String add5 = rs.getString("Phone"); txtPhone.setText(add5); } else { JOptionPane.showMessageDialog(this, "not found data"); } } catch (Exception e) { JOptionPane.showMessageDialog(this, e); } UPDATE CODE try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/susms","root",""); Statement std = (Statement) con.createStatement();
String qry ="update students set Name ='" + txtName.getText() + "', Gender='" + cboGender.getSelectedItem()+"', Address='" + txtAddress.getText()+ "', Phone='" + txtPhone.getText()+"'where ID='"+ txtID.getText()+"'"; int x = std.executeUpdate(qry); if (x==1) { JOptionPane.showMessageDialog(null, "updated suceesfully"); Filldata(); } else { JOptionPane.showMessageDialog(null, "update Failled"); } } catch (Exception e) { JOptionPane.showMessageDialog(this, e); } DELETE CODE try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/susms","root","");