Guest User

Untitled

a guest
Jul 1st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public class Conn {
  2. private Connection conn = null;
  3.  
  4.  
  5. public Connection getConn() throws ClassNotFoundException
  6. {
  7. try{
  8. Class.forName("com.mysql.jdbc.Driver");
  9. conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bloodbank","root","");
  10.  
  11. }catch(SQLException e){
  12. System.out.println(e);
  13. }
  14.  
  15. return conn;
  16. }
  17.  
  18. public void read() throws ClassNotFoundException, SQLException{
  19.  
  20. readForm r = new readForm();
  21. PreparedStatement st;
  22. Connection con = getConn();
  23. ResultSet rs;
  24.  
  25. String query = "SELECT * FROM patients";
  26. try {
  27. st = con.prepareStatement(query);
  28. rs = st.executeQuery();
  29. DefaultTableModel tm = (DefaultTableModel)r.table.getModel();
  30. tm.setRowCount(0);
  31. Object row[] = new Object[5];
  32. for(Patients u : list){
  33. row[0] = u.getId();
  34. row[1] = u.getfName();
  35. row[2] = u.getlName();
  36. row[3] = u.getGender();
  37. row[4] = u.getAge();
  38. tm.addRow(row);
  39. }
  40. r.setVisible(true);
  41. } catch (SQLException e) {
  42. System.out.println(e);
  43. }
  44. }
Add Comment
Please, Sign In to add comment