Enable an User Authentication in EmbeddedD Derby

I have a program that has a menu with two options first,to create a new database second,open existing database

my database creation part code is as follows

public EmbeddedDerby(String dbName, String userName, String pass) throws SQLException {
        String protocol = "jdbc:derby:";

        conn = DriverManager.getConnection(protocol + "dist/" + dbName + ""
                + ";create=true;user=" + userName + " " + ";password=" + pass + "");
        st = conn.createStatement();
        dbmd = conn.getMetaData();
        rs = dbmd.getTables(null, "APP", "DBNAME", null);
        String sqlTabel = "CREATE TABLE APP.DBNAME"
                + "(NAME VARCHAR(255) not null primary key,"
                + "TEL   VARCHAR(10))";
        st.execute(sqlTabel);
        }

my database opening part is as follows

 public void openDataBase(String dbName, String userName, String pass) throws SQLException {
        String protocol = "jdbc:derby:";
        conn = DriverManager.getConnection(protocol + "dist/" + dbName + ""
                + ";user=" + userName + ";password=" + pass + "");
        st = conn.createStatement();
        }

I have no issue with creating a new database, but when I want to open existing database, it does not check whether I enter a right username and password or not. Moreover, it accepts any username and password as long as name of a database exists. I thought getConnection method will check correctness of username and password, yet it seems I am totally wrong. Could anyone tell me what is wrong and how I can fix this issue?

Jon Skeet
people
quotationmark

From the documentation:

When user authentication is enabled (which it is not by default), the user requesting a connection must provide a valid name and password, which Derby verifies against the repository of users defined for the system.

Have you enabled user authentication? Again, from the documentation:

To enable user authentication, set the derby.connection.requireAuthentication property to true. Otherwise, Derby does not require a user name and password. You can set this property as a system-wide property or as a database-wide property.

For a multi-user product, you would typically set it for the system in the derby.properties file for your server, since it is in a trusted environment.

people

See more on this question at Stackoverflow