Created
May 15, 2013 23:17
-
-
Save Alcar32/5588192 to your computer and use it in GitHub Desktop.
Open a database connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.*; | |
Connection connection = null; | |
String driver = "org.apache.derby.jdbc.EmbeddedDriver"; | |
String connectionURL = "jdbc:derby:" | |
connectionURL += my_db_path; | |
try { | |
// load driver | |
Class.forName(driver); | |
} catch (ClassNotFoundException ex) { | |
// driver not found! | |
System.err.println(ex); | |
ex.printStackTrace(); | |
System.exit(1); // quit | |
} | |
try { | |
// try to access to db | |
connection = DriverManager.getConnection(connectinURL); | |
} catch (SQLException ex) { | |
// access failed! | |
System.err.println(ex); | |
ex.printStackTrace(); | |
System.exit(1); // quit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment