From: Heilveil, A. <alh...@sp...> - 2007-04-26 14:03:15
|
This is a fragment of what I do. It lets me handle the lock file still being around from an "abrupt program termination" (a crash ;). private void Connect() throws SQLException { synchronized (Hypersonic.class) {//#to get rid of 'lazy initialization not thread-safe' warning. if (driver == null) { driver = new org.hsqldb.jdbcDriver(); } //if we do the above when not necessary two copies of the driver get loaded. } try { String url = "jdbc:hsqldb:file:" + fullFilePath; log.info("connecting:" + url); //noinspection NestedTryStatement try { driver.connect(url, connectionProperties());//user,password, et al. } catch (SQLException e) { int traceCode = -e.getErrorCode(); String sqlState = e.getSQLState(); log.error(MessageFormat.format("database connect failed with traceCode:{0}, sql state:{1}", traceCode, sqlState)); switch (traceCode) { default: //try twice regardless of code, sometimes is wrapped a layer deeper as a generic java.lang.exception whose message is the tracecode. case Trace.LockFile_checkHeartbeat: //quick program restarts caught these case Trace.LockFile_checkHeartbeat2:// although unlocked the lock file has a timestamp that is too fresh. case Trace.DATABASE_ALREADY_IN_USE: deleteLock(); //try one more time. driver.connect(url, connectionProperties()); break; } } //# setWriteDelay is not useful, we generically call set autocommit ... which has the same effect as this: setWriteDelay(commitDelaySeconds); //note: schema may not exist yet. createInternals();//has side effect of early indications of trouble. } catch (SQLException e) { int traceCode = e.getErrorCode(); String sqlState = e.getSQLState(); log.error(MessageFormat.format("database connect failed again with traceCode:{0}, sql state:{1}", traceCode, sqlState)); throw e; } } _____ From: hsq...@li... [mailto:hsq...@li...] On Behalf Of Mehar SVLN Sent: Thursday, April 26, 2007 6:45 AM To: HSQLdb user discussions Subject: [Hsqldb-user] How to start a database with jdbc:hsqldb:file:///location as the url Hai friends To my knowledge, dabase with url like jdbc:hsqldb:file://// will start when connection is created. Is there a better way to start this database? -- Rgds Mehar |