Skip to content

Instantly share code, notes, and snippets.

@jomasero
Created February 6, 2014 19:08
Show Gist options
  • Select an option

  • Save jomasero/adc73a0355eb261fedb0 to your computer and use it in GitHub Desktop.

Select an option

Save jomasero/adc73a0355eb261fedb0 to your computer and use it in GitHub Desktop.
Abrir una conexión a base de datos en JAVA.
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