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);
}
}
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 ));
See Documentation.