我正在尝试在文本区域中显示控制台输出。
我有一个(视图)底部,它从类Functional
创建对象。在这个类中,有一个方法可以查看数据库中表的所有上下文,并返回查询结果并将其打印到控制台窗口中。所以我需要将控制台窗口的输出显示在GUI类的文本区域中。
这是GUI类:
public class MainGUI extends javax.swing.JFrame {
private void SearchButtonActionPerformed(java.awt.event.ActionEvent evt) {
Functional search = new Functional();
search.search(SearchTextField.getText(), ItemsComboBox.getSelectedItem().toString());
}
}
这是Functional
类:
public class Functional {
public void viewDtailes(String item) {
try (Connection con = DriverManager.getConnection("jdbc:odbc:Library_DNS");
Statement stmt = con.createStatement()) {
if(item.equals("magazins")){
String sql = "SELECT * FROM " + item;
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
System.out.println(" callNo : " + rs.getString("callno") + " title: " + rs.getString("title")+" Vnom :" + rs.getString("Vnom") + " status: " + rs.getBoolean("status"));
}
} else {
String sql = "SELECT * FROM "+ item;
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
System.out.println("callNo : " + rs.getString("callno")+ " title: " + rs.getString("title")+ " author :" + rs.getString("author") + " status: " + rs.getBoolean("status"));
}
}
} catch (SQLException sqle) {
System.out.println("Sql Exception :" +sqle.getMessage());
}
}
}
控制台的输出:
我需要在此文本区域GUI中显示控制台输出: