Tuesday, January 28, 2014

Dynamically pointing DomSQL to current database

I couldn't find a way to specify current database in the .jdbc file, so I dug around in the API.

When creating the connection to a DomSQL database, you can do it with getConnection and the name of a .jdbc config file:
public static Connection getConnection() throws SQLException {
    return JdbcUtil.getConnection( FacesContext.getCurrentInstance(), "nameOf.jdbc" );
}

Or use createConnection and specify the path for the connection:
public static Connection getConnection() throws SQLException {
    String dbPath = null;
    try {
        dbPath = ExtLibUtil.getCurrentDatabase().getFilePath().replaceAll( "\\\\", "/" );
    } catch( NotesException exception ){
        // Ignore
    }
  
    return JdbcUtil.createConnectionFromUrl( FacesContext.getCurrentInstance(), "jdbc:domsql:" + dbPath + "/nameOf.domsql" );
}


If you haven't heard of DomSQL: JDBC Access for IBM Domino

0 comments: