-1

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
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
vishal
  • 1,368
  • 2
  • 15
  • 34
  • Don't use 'quote formatting' for code! – Andrew Thompson Dec 31 '13 at 08:19
  • @AndrewThompson thanks for make my code good for ask – vishal Dec 31 '13 at 08:22
  • You have to issue a CREATE TABLE statement to created the IMPORTED_CSV table before you can select from it. Also, to get more information about what's going wrong on the Derby side: http://wiki.apache.org/db-derby/UnwindExceptionChain And learn to find your derby.log file on disk and read it, it will have more information, particularly if you run with -Dderby.language.logStatementText=true. – Bryan Pendleton Dec 31 '13 at 16:39
  • **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** 1. cd /home/path-to-dist 2. copy your db to path-to-dist folder. ie. /home/path-to-dist/embdIDA1db 3. java -jar app.jar – Sudhakar Krishnan Feb 25 '17 at 15:01

3 Answers3

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");
Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56
  • actually that url is for client side connection but i want my database is to be embedded with my application so that i use it at any other system i want – vishal Dec 31 '13 at 08:21
  • yes but it still throws same error – vishal Dec 31 '13 at 08:27
0

Can you please try this.

private static String dbURL = "jdbc:derby://localhost:1527/embdIDA1db;create=true;user=root;password=root";
Shashank Kadne
  • 7,993
  • 6
  • 41
  • 54
A Paul
  • 8,113
  • 3
  • 31
  • 61
  • actually that url is for client side connection but i want my database is to be embedded with my application so that i use it at any other system i want – vishal Dec 31 '13 at 08:23
0

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>