我是德比数据库的新手,我正在努力 恢复derby数据库的备份 使用apache教程中的代码。 但它给出了一个错误,没有找到适合德比的驱动程序, 我随时运行代码。
以下是代码段:
public void restoreDatabase()
{
try {
String dbURL = "jdbc:derby:/localhost:1527/NSS_DB;restoreFrom="
+ "c:/mybackups/2013-03-31/NSS_DB";
Connection conn = DriverManager.getConnection(dbURL);
conn.close();
System.out.println("restore wassuccessful ");
} catch (SQLException ex) {
Logger.getLogger(MyJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
修改代码后,我不再收到错误,但备份无法恢复。以下是对上述代码的修改。这是第二个代码段。
public void restoreDatabase() throws ClassNotFoundException
{
try {
String dbURL = "jdbc:derby://localhost:1527/NSS_DB;restoreFrom="
+ "c:/mybackups/2013-03-31/NSS_DB";
Connection conn = null;
Properties props = new Properties();
props.put("user", uName);
props.put("password", uPass);
conn = DriverManager.getConnection(dbURL, props);
conn.commit();
} catch (SQLException ex) {
Logger.getLogger(MyJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
我认为唯一的添加是使用java.util.Properties对象。
来自Netbeans控制台的此错误消息由第一个代码片段生成
Apr 01, 2013 8:39:25 PM my.gnssregsitry.DBSearch restoreDatabase
SEVERE: null
java.sql.SQLException: No suitable driver found for jdbc:derby:/localhost:1527/NSS_DB;restoreFrom=c:/mybackups/2013-03-31/NSS_DB
at java.sql.DriverManager.getConnection(DriverManager.java:604)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at my.gnssregsitry.DBSearch.restoreDatabase(DBSearch.java:242)
at my.gnssregsitry.MyJFrame.jButton2ActionPerformed(MyJFrame.java:929)
at my.gnssregsitry.MyJFrame.access$1900(MyJFrame.java:41)
at my.gnssregsitry.MyJFrame$20.actionPerformed(MyJFrame.java:591)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
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)
看起来代码还有很多工作要做 任何siggestions
答案 0 :(得分:0)
不合适的驱动程序问题意味着:(a)你必须将derbyclient.jar放入你的类路径中,并且(b)你可能必须调用Class.forName(“org.apache.derby.jdbc.ClientDriver” “);
此外,“localhost”前面应该有两个斜杠;它应该是“jdbc:derby:// localhost:1527 / NSS_DB; restoreFrom = ...”等。