我有疑问 - 如何将结果/数据库选择写入 JTextArea。我的 JButton 的方法是:
public void actionPerformed(ActionEvent evt){
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connection OK");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/filisng", "root", "passw");
statement = connection.createStatement();
result = statement.executeQuery("select * from `filisng`.`names`");
while(result.next()){
String nam = result.getString("Name");
String surnam = result.getString("Surname");
System.out.printf("Name: %s\tSurname: %s\t\n", Name, Surname);
}
}catch(ClassNotFoundException ex){System.out.println("Class Not Found! " +ex);
}catch(SQLException exception){
System.out.println("SQL Error " + exception);
}
}
如果我使用System.out.printf("Name: %s\tSurname: %s\t\n", Name, Surname);
- 我在控制台中看到输出,但是如何将 Text 设置为 JTextArea?