I want to display values from database in many lines using jLabel. I tried using the html trick but I don't know how to apply it here in my code. I just get errors. Maybe I'm doing it the wrong way. Haha.
try{
//display doctor's name by selected classification
String url = "jdbc:mysql://localhost/sched";
Connection conn = DriverManager.getConnection(url,"root","");
Statement stmt = conn.createStatement();
String classification = comboClass.getSelectedItem().toString();
String sqlSelect= "select * from doctorsched where class = '"+classification+"'";
ResultSet rs = stmt.executeQuery(sqlSelect);
String finalText ="";
while(rs.next()){
String docsName= rs.getString("docName");
String room = rs.getString("room");
String days = rs.getString("day");
String from = rs.getString("timefrom");
String to = rs.getString("timeto");
finalText += docsName+" (room "+room+", "+days+", "+from+"-"+to+") \\n";
// i want to display values from database in many lines but using jLabel
}
jLabel10.setText(finalText);
} catch (Exception ex) {
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
Something like this should be my output
doc riza (room 104, Every Thursday, 10:30AM-10:00AM)
doc j (room 101, null, 10:30AM-11:30AM)
doc lea (room 102, Every Saturday, 10:30AM-4:30PM)
frida (room 101, null, 8:00AM-9:30AM)
Please help me out :( The '\n' works in jTextArea but not in jLabel. I also tried '\n' in label, but doesn't work, too.
Okay so I tried this one
finalText += "<html>"+docsName+" (room "+room+", "+days+", "+from+"-"+to+")<br></html>";
But this code only display one line. The first row in my database. I need to display all of the rows.
Now, this next code shows it all, but the next line still doesn't work.
while(rs.next()){
String docsName= rs.getString("docName");
String room = rs.getString("room");
String days = rs.getString("day");
String from = rs.getString("timefrom");
String to = rs.getString("timeto");
finalText += docsName+" (room "+room+", "+days+", "+from+"-"+to+")\n";
}
jLabel10.setText("<html>"+finalText+"<br></html>");
}
Whyyy
"; Like this. But it only displays the first row from my database. – Rica Jacutina Nov 14 '20 at 10:05