How can I get multiple rows from database and display it all either in jTextArea or in a jLabel?
try{
String url = "jdbc:mysql://localhost/sched";
Connection conn= DriverManager.getConnection(url,"root", "");
Statement stmt =conn.createStatement();
String classif=comboClass.getSelectedItem().toString();
String sqlSelect="select * from doctorsched where class = '"+classif+"'";
ResultSet rs= stmt.executeQuery(sqlSelect);
while(rs.next()){
String docsName=rs.getString("docsName");
String room=rs.getString("room");
jTextArea1.setText(docsName+" (room "+room+") \n");
}
}catch(Exception e){
}
When I use this code, jTextArea1 only displays data from the last line or row of the database. The rest from the beginning is not visible. And if I'll use jLabel I'm sure it would also work this way. These two (jLabel and jTextArea) are my only options for this.
If someone could help me, I'd appreciate it so much. Thank you.