I'm trying to display the console output in a text area.
I have a (view) bottom that creates object from class Functional
. Inside this class there is method that view all the context of table in table in data base and return the result of the query and printed it into the console window. So I need to display this output from the console window to a text area in the GUI class .
This is the GUI class:
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());
}
}
This is the Functional
class:
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());
}
}
}
The output from console:
I need to display the console output in this text area GUI: