Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Conn {
- private Connection conn = null;
- public Connection getConn() throws ClassNotFoundException
- {
- try{
- Class.forName("com.mysql.jdbc.Driver");
- conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bloodbank","root","");
- }catch(SQLException e){
- System.out.println(e);
- }
- return conn;
- }
- public void read() throws ClassNotFoundException, SQLException{
- readForm r = new readForm();
- PreparedStatement st;
- Connection con = getConn();
- ResultSet rs;
- String query = "SELECT * FROM patients";
- try {
- st = con.prepareStatement(query);
- rs = st.executeQuery();
- DefaultTableModel tm = (DefaultTableModel)r.table.getModel();
- tm.setRowCount(0);
- Object row[] = new Object[5];
- for(Patients u : list){
- row[0] = u.getId();
- row[1] = u.getfName();
- row[2] = u.getlName();
- row[3] = u.getGender();
- row[4] = u.getAge();
- tm.addRow(row);
- }
- r.setVisible(true);
- } catch (SQLException e) {
- System.out.println(e);
- }
- }
Add Comment
Please, Sign In to add comment