Guest User

Untitled

a guest
Jan 4th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Connection connection;
  2. try {
  3. // this is hard fix for example, ~/hsqldb-2.3.3.jar should be gotten from a setting file
  4. File jdbcJarFile = new File("~/hsqldb-2.3.3.jar");
  5. URL urls[] = { jdbcJarFile.toURI().toURL() };
  6. URLClassLoader loader = new URLClassLoader(urls, DatabaseUtil.class.getClassLoader());
  7. Thread.currentThread().setContextClassLoader(loader);
  8. loader.loadClass("org.hsqldb.jdbcDriver");
  9.  
  10. // no error but nothing happens
  11. Class.forName("org.hsqldb.jdbcDriver", true, loader);
  12.  
  13. // throw exception because cannot find the driver for HSQL DB
  14. // with this url: jdbc:hsqldb:file://home/abc/hsqldb/test
  15. connection = DriverManager.getConnection(datasourceURL, datasourceUserName, datasourcePassword);
  16. } catch(Exception ex) {
  17. // (java.sql.SQLException) java.sql.SQLException: No suitable driver found for jdbc:hsqldb:file://home/abc/hsqldb/test
  18. throw new SQLException(ex);
  19. }
Add Comment
Please, Sign In to add comment