witam, chciałem wyświetlić zawartość bazy danych w trzech kolumnach w wierszu poleceń, baza natomiast wyświetla się w jednej kolumnie i chciałem prosić o wskazanie błędu, o to kod:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javasqluzytkownicy;
import java.sql.*;
/**
*
* @author marcin
*/
public class WyswietlanieUzytkownikow {
static final String ADRES_BAZY = "jdbc:mysql://localhost/uzytkownicy";
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
public WyswietlanieUzytkownikow() {
try{
connection = DriverManager.getConnection(ADRES_BAZY, "root", "qwerty12nm");
statement = connection.createStatement();
resultSet = statement.executeQuery("select id, imie, nazwisko from dane");
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int numerId = resultSetMetaData.getColumnCount();
System.out.println("baza danych uzytkownicy\n");
for(int i = 1; i <= numerId; ++i){
System.out.printf("%-8s\t", resultSetMetaData.getColumnName(i));
System.out.println();
while(resultSet.next()){
for(i = 1; i <= numerId; ++i){
System.out.printf("%-8s\t", resultSet.getObject(i));
System.out.println();
}
}
}
}catch(SQLException sQLException){
sQLException.printStackTrace();
}
finally{
try{
resultSet.close();
statement.close();
connection.close();
}catch(Exception exception){
exception.printStackTrace();
}
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javasqluzytkownicy;
/**
*
* @author marcin
*/
public class JavaSqlUzytkownicy {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
WyswietlanieUzytkownikow wyswietlanieUzytkownikow = new WyswietlanieUzytkownikow();
}
}