load the driver explicitly
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Mon, 12 Dec 2011 14:46:33 +0000 (14:46 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Mon, 12 Dec 2011 14:46:33 +0000 (14:46 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4813 e3abac25-378b-4346-85de-24260fe3988d

webservices/compbio/stat/collector/StatDB.java

index 7073fc1..b469c44 100644 (file)
@@ -58,19 +58,26 @@ public class StatDB {
                if (conn != null && !conn.isClosed()) {\r
                        return conn;\r
                } else {\r
-                       String dbpath = PropertyHelperManager.getLocalPath();\r
-                       log.info("Looking for JABAWS access statistics database at: "\r
-                                       + dbpath);\r
-                       System.setProperty("derby.system.home", dbpath);\r
-                       conn = DriverManager.getConnection(protocol + statDBName\r
-                                       + ";create=false");\r
-\r
-                       conn.setAutoCommit(true);\r
-                       /*\r
-                        * Runtime.getRuntime().addShutdownHook(new Thread() {\r
-                        * \r
-                        * @Override public void run() { shutdownDBServer(); } });\r
-                        */\r
+                       try {\r
+                               String dbpath = PropertyHelperManager.getLocalPath();\r
+                               log.info("Looking for JABAWS access statistics database at: "\r
+                                               + dbpath);\r
+                               System.setProperty("derby.system.home", dbpath);\r
+                               // Apparently under Tomcat webapp you cannot rely on Java\r
+                               // auto discovery and have to register the driver explicitly\r
+                               Class.forName(driver);\r
+                               conn = DriverManager.getConnection(protocol + statDBName\r
+                                               + ";create=false");\r
+\r
+                               conn.setAutoCommit(true);\r
+                               /*\r
+                                * Runtime.getRuntime().addShutdownHook(new Thread() {\r
+                                * \r
+                                * @Override public void run() { shutdownDBServer(); } });\r
+                                */\r
+                       } catch (ClassNotFoundException e) {\r
+                               log.error(e.getMessage(), e);\r
+                       }\r
                }\r
                return conn;\r
        }\r