错误是java.sql.SQLSyntaxErrorException:架构'ROOT'不存在

时间:2013-12-31 08:13:49

标签: java jdbc syntax-error derby

我正在创建使用derby嵌入式数据库的桌面应用程序,虽然当我使用derby作为客户端数据库然后它工作正常,但我想用我的桌面应用程序嵌入这个数据库然后它抛出错误 下面是帮助代码,请查看

public class TaxInvoice extends javax.swing.JFrame {

 //String connectionurl = "jdbc:derby://localhost:1527/embdIDA1db";

 String connectionurl = "jdbc:derby:embdIDA1db;create=true;user=root;password=root";

 Connection conn = null; 

 ResultSet rs;

 String po_no = null;

/**
 * Creates new form TaxInvoice
 */
public TaxInvoice() {
    initComponents();
    String dt = sdf.format(cal.getTime());
    cur_date.setText(dt);
    try{
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        conn = DriverManager.getConnection(connectionurl,"root","root");
        String sql="Select * from IMPORTED_CSV";
        Statement s = conn.createStatement();
        s.executeQuery(sql);
        rs = s.getResultSet();
        while(rs.next()){
            po_no = rs.getString("PO_NO");
            jTextField1.setText(po_no);
        }
        rs.close();
        s.close();
    }
    catch(Exception e){
        System.out.println("Error is"+e);
    }
}

,错误是

Error isjava.sql.SQLSyntaxErrorException: Schema 'ROOT' does not exist

3 个答案:

答案 0 :(得分:1)

您的connectionURl应为jdbc:derby://localhost:1527/embdIDA1db,这似乎在您的代码中被注释掉了。

您正在明确传递用户名和密码,因此无需将其包含在网址中。

DriverManager.getConnection(connectionurl,"root","root");

答案 1 :(得分:0)

请你试试这个。

private static String dbURL = "jdbc:derby://localhost:1527/embdIDA1db;create=true;user=root;password=root";

答案 2 :(得分:0)

为了完成这项工作,
使用默认模式进行德比 即用户="应用"密码=""

例如:

       try 
        {
            // Configures and loads Database
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            Connection conn = DriverManager.getConnection("jdbc:derby:myDB;create=true", "APP" , "");

        } catch (Exception ex) 
        {
            System.out.println(ex);
        }  

或者您可以使用

创建架构
CREATE SCHEMA <schema name>
相关问题