This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 184375 - Create database uses username as schema, misconfigures new database.
Summary: Create database uses username as schema, misconfigures new database.
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Derby (show other bugs)
Version: -S1S-
Hardware: PC Windows 7 x64
: P3 normal (vote)
Assignee: Jiri Rechtacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-16 19:16 UTC by charlweed
Modified: 2011-10-20 14:23 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description charlweed 2010-04-16 19:16:54 UTC
Derby Databases are not created correctly. The USERNAME argument is used where the SCHEMA argument should be. This misconfigures the connections, and the database. Even if you fix the connection, when an attempt is made to use the SQL editor, it always fails with “Error code -1, SQL state 42Y07: Schema '<username>' does not exist”


This can be seen when the database is created, in the file
userdir/config/Databases/Connections/jdbc_derby__localhost_1527_<database>.xml

Note that the schema should be “APP” instead it is NBUSER, which is the username:

<?xml version='1.0'?>
<!DOCTYPE connection PUBLIC '-//NetBeans//DTD Database Connection 1.1//EN' 'http://www.netbeans.org/dtds/connection-1_1.dtd'>
<connection>
  <driver-class value='org.apache.derby.jdbc.ClientDriver'/>
  <driver-name value='apache_derby_net'/>
  <database-url value='jdbc:derby://localhost:1527/duplicatefile'/>
  <schema value='NBUSER'/>
  <user value='nbuser'/>
  <password value='cGFzc3dvcmQ='/>
</connection>


Manually fixing this one file is not sufficient, as schema is still messed up elsewhere in the database.
Comment 1 charlweed 2010-04-16 19:58:07 UTC
The problem may be in 
org.netbeans.modules.derby.DerbyDatabasesImpl.java, line 274

        return registerDatabase(databaseName, user,
                setupAuthentication ? user.toUpperCase() : "APP", // NOI18N
                setupAuthentication ? password : null, setupAuthentication);

Looks to me like the 3rd parameter should just be "APP", because that parameter is supposed to be the schema.

I deleted 'setupAuthentication ? user.toUpperCase() :' from line  274 
and Create Database now has the expected behavior.
Comment 2 charlweed 2010-04-26 19:13:24 UTC
BTW, I may know WHY this may have been the design choice.
By default, when the user connects, the default schema used is the all-caps username. 

http://db.apache.org/derby/faq.html#schema_exist

Unfortunately:
)This default schema is not automatically created.
)Attempting to connect to the non-existing schema breaks connections

So, a common strategy is to always create a schema with the all-caps username when the database is created. This can be ok when the database is first created. I don’t know why it failed in this case. However, when a new user tries to follow the NetBeans  “Database Application” tutorial, it will fail, because the tutorial and all the other GUI tools and whatever expect the “APP” schema.

Derby’s behavior in this matter is pretty weird, and it’s easy for developers to go wrong.

As noted in this blog, it may be best to create a
   …custom authentication class - it’s not as hard as it seems. All you need to do is to implement org.apache.derby.authentication.UserAuthenticator  interface and use some other connection properties to authenticate your users.
Comment 3 Jiri Rechtacek 2011-10-19 12:48:42 UTC
Thanks for evaluation this problem. I hope that fix made it better.
core-main/rev/e1306a56f747
Comment 4 Quality Engineering 2011-10-20 14:23:31 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/e1306a56f747
User: Jiri Rechtacek <jrechtacek@netbeans.org>
Log: #184375: Create database uses username as schema, misconfigures new database