错误是 java.sql.SQLSyntaxErrorException: Schema 'ROOT' 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20854122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error is java.sql.SQLSyntaxErrorException: Schema 'ROOT' does not exist
提问by vishal
i am creating desktop application which uses derby embedded database, although when i use derby as a client database then it works fine, but i want to embed this database with my desktop application then it throws error below is the code for help, check it out
我正在创建使用 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);
}
}
and the error is
错误是
Error isjava.sql.SQLSyntaxErrorException: Schema 'ROOT' does not exist
回答by Prasad Kharkar
Your connectionURl should be jdbc:derby://localhost:1527/embdIDA1db
which seems to be commented out in your code.
您的 connectionURl 应该jdbc:derby://localhost:1527/embdIDA1db
在您的代码中被注释掉。
Your are passing username and password explicitly so there is no need to include them in url.
您正在明确传递用户名和密码,因此无需将它们包含在 url 中。
DriverManager.getConnection(connectionurl,"root","root");
回答by A Paul
Can you please try this.
你能试试这个吗。
private static String dbURL = "jdbc:derby://localhost:1527/embdIDA1db;create=true;user=root;password=root";
回答by A Paul
To make this work,
use default schema for derby
i.e. user="App" password = ""
要使其工作,请
使用 derby 的默认模式,
即 user="App" password = ""
eg :
例如:
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);
}
or you can create schema using
或者您可以使用创建架构
CREATE SCHEMA <schema name>