0
我有一些代碼,加載什麼: 1)HSQLDB v 2.2.8捆綁 2)與捆綁服務:HSQLDB束未發現
package ihtika2.i_internalfunctions.service;
import com.google.code.ihtika.Vars.Ini;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.DriverManager;
/**
*
* @author Arthur
*/
public class InternalFunctions implements InternalFunctionsInterface {
// launch browser
public void launchBrowser(String uriStr) {
Desktop desktop;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
// launch browser
URI uri;
try {
uri = new URI("http://" + uriStr);
desktop.browse(uri);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (URISyntaxException use) {
use.printStackTrace();
}
}
}
}
public void initDB() {
try {
Class.forName("org.hsqldb.jdbcDriver");
Ini.conn = DriverManager.getConnection("jdbc:hsqldb:file:Db/pages");
Ini.stmt = Ini.conn.createStatement();
Ini.rs = null;
Ini.rs = Ini.stmt.executeQuery("select count(1) as qwe from "
+ " information_schema.system_tables "
+ "where table_schem = 'PUBLIC'"
+ "and table_name = 'PAGES';");
Ini.rs.next();
if (Ini.rs.getInt("qwe") == 0) {
Ini.stmt.executeUpdate("CREATE SEQUENCE SEQU");
Ini.stmt.executeUpdate("CREATE CACHED TABLE PAGES (id bigint "
+ "GENERATED BY DEFAULT AS SEQUENCE SEQU PRIMARY KEY, "
+ "url varchar(7777), lastUpdateDate varchar(7777)) ");
Ini.stmt.executeUpdate("CREATE CACHED TABLE LINKDATA (id int, "
+ "nazvanie varchar(777), linkURL varchar(777), razmer varchar(777)) ");
Ini.stmt.executeUpdate("CREATE INDEX linkDataID ON LINKDATA (id)");
Ini.stmt.executeUpdate("CREATE INDEX pagesURL ON PAGES (url)");
}
} catch (Exception ex) {
Ini.logger.fatal("Error on DB init", ex);
}
}
}
3)有些包,什麼叫捆數2
try {
ServiceReference[] refs = context.getServiceReferences(
InternalFunctionsInterface.class.getName(), "(Funct=IFuncts)");
if (refs == null) {
System.out.println("Not Found IFuncts on init");
} else {
InternalFunctions = (InternalFunctionsInterface) context.getService(refs[0]);
}
} catch (Exception ex) {
Ini.logger.fatal("Error on IFuncts init", ex);
}
InternalFunctions.initDB();
上執行我得到了記錄錯誤:
[FATAL] 2012-08-02 20:18 root (InternalFunctions.java:initDB:61)
Error on DB init
java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver not found by ihtika2.I_InternalFunctions [7]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at ihtika2.i_internalfunctions.service.InternalFunctions.initDB(InternalFunctions.java:40)
at ihtika2.mainform.IC_MainForm.<init>(IC_MainForm.java:66)
at ihtika2.mainform.IC_MainForm$4.run(IC_MainForm.java:225)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
請教,如何在其他包中使用HSQLDB包?
由我回答: 的解決方案是使用
DriverManager.registerDriver(new JDBCDriver());
Ini.conn = DriverManager.getConnection("jdbc:hsqldb:file:Db/pages");
insted的使用
Class.forName("org.hsqldb.jdbcDriver");
Ini.conn = DriverManager.getConnection("jdbc:hsqldb:file:Db/pages");
如果您發現自己問題的解決方案,請將其作爲答案發布,而不是編輯自己的問題。然後你可以接受這個答案,這樣別人就可以看到它被解決了。 – 2012-08-02 18:21:18