Created
February 6, 2014 19:08
-
-
Save jomasero/adc73a0355eb261fedb0 to your computer and use it in GitHub Desktop.
Abrir una conexión a base de datos en JAVA.
This file contains hidden or 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