public class library2 {
private Connection connect = null;
private Statement statement = null;
private ResultSet resultSet = null;
public void readDataBase() throws Exception {
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///librarydb",
"root", "123123");
st = con.createStatement();
rs = st.executeQuery("SELECT firstName, address, FROM customer");
while(rs.next()) {
int userId = rs.getInt(1);
String firstName = rs.getString(2);
String address = rs.getString(3);
System.out.println(userId + ". " + address + ", " +
firstName);
}
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(rs != null)
rs.close();
if(st != null)
st.close();
if(con != null)
con.close();
} catch (SQLException e) {
}
}
}
}