Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- try {
- String dbURL = "MYSQL";
- String username = "produngeon";
- String password = "password";
- Class.forName("com.mysql.jdbc.Driver");
- conn =
- DriverManager.getConnection(dbURL, username, password);
- stmt = conn.createStatement();
- if (stmt.execute("select * from testing")) {
- rs = stmt.getResultSet();
- } else {
- System.err.println("select failed");
- }
- while (rs.next()) {
- String entry = rs.getString(1);
- System.out.println(entry);
- }
- } catch (ClassNotFoundException ex) {
- System.err.println("Failed to load mysql driver");
- System.err.println(ex);
- } catch (SQLException ex) {
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- System.out.println("VendorError: " + ex.getErrorCode());
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException ex) { /* ignore */ }
- rs = null;
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException ex) { /* ignore */ }
- stmt = null;
- }
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException ex) { /* ignore */ }
- conn = null;
- }
- }
- }
Add Comment
Please, Sign In to add comment