package pt.iscte.ci.aop.pooling; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class Test { public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); printTable("jdbc:mysql://localhost:3306/dev_fenix_pacza", "DEPARTMENT", "root", ""); printTable("jdbc:mysql://localhost:3306/dev_fenix_pacza", "DEPARTMENT", "pacza", "mafalda"); printTable("jdbc:mysql://localhost:3306/dev_fenix_pacza", "DEPARTMENT", "root", ""); printTable("jdbc:mysql://localhost:3306/dev_fenix_pacza", "DEPARTMENT", "pacza", "mafalda"); } private static void printTable(String url, String table, String username, String password) throws SQLException { final Connection connection = DriverManager.getConnection(url, username, password); final Statement statement = connection.createStatement(); final ResultSet rs = statement.executeQuery("SELECT * FROM " + table); final ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); while(rs.next()) { for(int i = 1; i < numberOfColumns + 1; ++i) { System.out.println(rs.getString(i) + "\t"); } System.out.println(); } rs.close(); connection.close(); } }