Search code examples
javaderbyjavadb

Java Derby Create Database with dotted username


I can not create database with below connectionUrl;

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
String connectionUrl = "jdbc:derby:myDB;create=true;user="+"john.smith"+";password="+"johnpassword"+";";
Connection con = DriverManager.getConnection(connectionUrl);
java.sql.Statement stmt = con.createStatement();

When i use johnsmith for username it is successfully created. I suspect the dots are causing a problem.

What am I doing wrong?


Solution

  • You must put double quotes around the user=john.smith ( symbol " needs to be escaped with \ in java), because it(Dot) is not a valid ordinary Identifier.

    String connectionUrl = "jdbc:derby:myDB;create=true;user="+"\"john.smith\""+";password="+"johnpassword"+";";