问题
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
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
回答1:
Your connectionURl should be jdbc:derby://localhost:1527/embdIDA1db
which seems to be commented out in your code.
Your are passing username and password explicitly so there is no need to include them in url.
DriverManager.getConnection(connectionurl,"root","root");
回答2:
Can you please try this.
private static String dbURL = "jdbc:derby://localhost:1527/embdIDA1db;create=true;user=root;password=root";
回答3:
To make this work,
use default schema for derby
i.e. 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>
来源:https://stackoverflow.com/questions/20854122/error-is-java-sql-sqlsyntaxerrorexception-schema-root-does-not-exist