0

我是 derby 数据库的新手,我正在尝试使用 apache 教程中的代码恢复 derby 数据库的备份。但是,无论何时我运行代码,它都会给出一个错误,即找不到适合 derby 的驱动程序。

以下是代码片段:

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

4

1 回答 1

0

没有合适的驱动程序问题意味着:(a)您必须将 derbyclient.jar 放入您的类路径中,并且(b)您可能必须调用 Class.forName( "org.apache.derby.jdbc.ClientDriver" );

另外,“localhost”前面应该有两个斜杠;它应该是“jdbc:derby://localhost:1527/NSS_DB;restoreFrom=...”等。

于 2013-04-02T00:27:52.320 回答