Java - JDBC - selectStatement
public void selectStatement() throws SQLException {
try {
conn = DB_Util.getConn(DB_Types.MYSQLDB);
stmnt = conn.createStatement();
rs = stmnt.executeQuery("select Code, Name, Continent from Country limit 20");
String format = "%-10s%-50s%-20s\n";
while (rs.next()) {
System.out.format(format, rs.getString("Code"), rs.getString("Name"), rs.getString("Continent"));
}
}
catch (SQLException e) {
DB_Util.getErrorMessage(e);
}
finally {
rs.close();
stmnt.close();
conn.close();
}
}