本文介绍了如何将结果写入JTextArea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有疑问 - 如何编写结果/数据库选择到JTextArea。我的JButton方法是:
I have question - how to write result/ DB Select to JTextArea. My JButton´s method is:
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);
- 我在Console中看到输出但是,如何设置文本到JTextArea?
If I use System.out.printf("Name: %s\tSurname: %s\t\n", Name, Surname);
- I see output in Console but, how to set Text to JTextArea?
推荐答案
textArea.append( String.format( "Name: %s\tSurname: %s\t\n", Name, Surname ));
参见。
这篇关于如何将结果写入JTextArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!