I think I know why your program is not working... You are not passing username/password as the URL attributes... If you change:

            Connection conn  =  DriverManager.getConnection("jdbc:derby:/tmp/TestDB", prop);
To
            Connection conn  =  DriverManager.getConnection("jdbc:derby:/tmp/TestDB;user=username;password=password");

It should work. Or you can create the Properties object and set username/password using correct property names, user/password, it should also work. Currently, you are setting username/password using:

    prop.setProperty("derby.user.username", "password");

Once you do manage to connect to your database, you may notice other issues... When you connect to Derby using a valid username, your schema is the 'username', not the default APP.

Satheesh

Arne Anka wrote:
hi,
i'm fairly new to derby and experience a problem absolutely not clear to  me.
programming an java-application (rcp-based, if it matters) i create a  database programmatically with two tables, reading and writing works well.
i restart my application, try to access the db with  _exactly_the_same_code_ ... and get the error mentioned in the subject!
-------- Derby Information --------
JRE - JDBC: J2SE 5.0 - JDBC 3.0
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derby.jar]  10.1.1.0 - (208786)
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derbyclient.jar]  10.1.1.0 - (208786)
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derbytools.jar]  10.1.1.0 - (208786)
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derbynet.jar]  10.1.1.0 - (208786)
------------------------------------------------------

it works well, if i create and access the db in a single session. if try  to access the db in another session later on,
Connection conn  = DriverManager.getConnection("jdbc:derby:/tmp/TestDB",  prop); yields

SQL Exception: Connection refused : Invalid authentication.
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown  Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown  Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown  Source)
        at  org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
        at  org.apache.derby.impl.jdbc.EmbedConnection.checkUserCredentials(Unknown  Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown  Source)
        at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown  Source)
        at org.apache.derby.jdbc.Driver30.getNewEmbedConnection(Unknown  Source)
        at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
        at java.sql.DriverManager.getConnection(DriverManager.java:140)
        at  de.itcputbus.marinasw.main.dblocal.LocalDBStuff.readEmbedded(LocalDBStuff.java:181)
        ...

code to create and access (if you find a typo -- the code i use is  syntactically correct, i probabyl introduced it here)


 public static void initEmbedded() {
                try{
                   //prop is a java.utils.Properties instance
                   prop.setProperty("derby.user.username", "password");
                   prop.setProperty("derby.system.home",  dbpath.removeLastSegments(1).toOSString());
                   prop.setProperty("derby.connection.requireAuthentication",  "true");
                   prop.setProperty("derby.database.fullAccessUsers",  "dba,username");
                   prop.setProperty("derby.authentication.provider",  "BUILTIN");
                    System.setProperty("derby.system.home",  dbpath.removeLastSegments(1).toOSString());

                    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

                }catch(Exception e){
                    e.printStackTrace();
                }
        }
    }

    public static void createEmbedded(){
        try{
            Connection conn  =  DriverManager.getConnection("jdbc:derby:/tmp/TestDB;create=true", prop);
            Statement s = conn.createStatement();

            s.addBatch("CALL  SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.connection.requireAuthentication','true')");
            s.addBatch("CALL  SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user.username','password')");
            s.addBatch("CALL  SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.fullAccessUsers',  'dba,username')");
            s.addBatch("CALL  SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.authentication.provider',  'BUILTIN')");

            s.executeBatch();

            try{//derby does not know "drop table if exists" but yields an  error if the table to drop not exists -- so we need a workaround ...
                s.execute("drop table custs");
                s.execute("drop table orders");
            }catch(SQLException e) {}

            s.addBatch("create table custs (id char(5) not null, name  char(40) not null, primary key(id))");
            s.addBatch("create table orders (id char(8) not null, custid  char(5) not null, total integer, primary key(id, custid))");

            s.executeBatch();

            s.addBatch("insert into custs values('1', 'John Milton')");
            s.addBatch("insert into custs values('2', 'Duns Scotus')");

            s.executeBatch();

            s.addBatch("insert into orders values('0001', '1', 12345)");
            s.addBatch("insert into orders values('0002', '2', 145)");

            s.executeBatch();

            conn.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static void readEmbedded(){
        try{
            Connection conn  =  DriverManager.getConnection("jdbc:derby:/tmp/TestDB", prop);
            ResultSet rs=conn.createStatement().executeQuery("select *  from custs, orders");
            while(rs.next()) {
                System.out.println("-: "+rs.getString(1)+" |  "+rs.getString(2)+" | "+rs.getString(3)+" | "+rs.getString(4)+" |  "+rs.getString(5));
            }
            conn.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }