I'm printing my output from MySQL queries in my console, and into the text area in my gui application. Right now, the columns get messed up in the text area any time a name is longer than the width of its column. How can I fix the segment of code below to make the output to the text area look uniform?
else if (e.getSource() == executeButton) {
//Create a statement
try{
String commandString = enterSQLText.getText();
Statement statement = conn.createStatement();
//Execute a statement
ResultSet resultSet = statement.executeQuery(commandString);
//Process query results
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
for(int i = 1; i<= numberOfColumns; i++){
executionResultText.append(metaData.getColumnName(i) + "\t");
System.out.printf("%20s\t", metaData.getColumnName(i));
}
executionResultText.append("\n");
System.out.println();
while (resultSet.next()){
for (int i = 1; i <= numberOfColumns; i++){
executionResultText.append(resultSet.getObject(i).toString() + "\t");
System.out.printf("%20s\t", resultSet.getObject(i));
}
executionResultText.append("\n");
System.out.println();
}
System.out.println("Execute Button Works!");
}
catch (Exception h){
h.printStackTrace();
}
}
I appreciate the help.