Question

I'm trying to connect to a derby database.

I have the following error in the console after running the app:

    01:07:31.698 [main] INFO  o.s.j.d.DriverManagerDataSource - Loaded JDBC driver: org.apache.derby.jdbc.EmbeddedDriver
Creating records
01:07:31.826 [main] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL update
01:07:31.828 [main] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL statement [INSERT INTO `students` (name,age) VALUES (?,?)]
01:07:31.845 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
01:07:31.845 [main] DEBUG o.s.j.d.DriverManagerDataSource - Creating new JDBC DriverManager Connection to [jdbc:derby:c:\temp\database\test01;create=true]
Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Failed to start database 'c:\temp\database\test01' with class loader sun.misc.Launcher$AppClassLoader@6d9bf996, see the next exception for details.
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:628)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:907)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:968)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:978)
    at Student.dao.StudentImplementationOfDao.insert(StudentImplementationOfDao.java:22)
    at main.Application.main(Application.java:31)
Caused by: java.sql.SQLException: Failed to start database 'c:\temp\database\test01' with class loader sun.misc.Launcher$AppClassLoader@6d9bf996, see the next exception for details.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(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.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
    at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
    at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ... 6 more
Caused by: java.sql.SQLException: Failed to start database 'c:\temp\database\test01' with class loader sun.misc.Launcher$AppClassLoader@6d9bf996, see the next exception for details.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
    ... 24 more
Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database C:\temp\database\test01.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
    ... 21 more
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database C:\temp\database\test01.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
    at org.apache.derby.impl.store.raw.RawStore.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
    at org.apache.derby.impl.store.access.RAMAccessManager.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
    at org.apache.derby.impl.db.BasicDatabase.bootStore(Unknown Source)
    at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startProviderService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.findProviderAndStartService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startPersistentService(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.startPersistentService(Unknown Source)
    ... 21 more

The code that I built to connect to the database is:

        DriverManagerDataSource ds = new DriverManagerDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    ds.setUrl("jdbc:derby:c:\\temp\\database\\test01;create=true");
    ds.setUsername("");
    ds.setPassword("");
    siod.setDataSource(ds);

From what I could understand in the errors shown above is something to do with a PreparedStatement that tries to gets inserted.

The sql statement is:

"INSERT INTO `students` (name,age) VALUES (?,?)

I parsed this sql to a instantiated JdbcTemplate which has the dataSource mentioned above. Here is the exact code:

public void insert(Student student)
{
//ds is simply the dataSource that gets created in the code example above
JdbcTemplate create = new JdbcTemplate(ds);
create.update(sql,new Object[]{student.name,student.age});

}

I'm sure this question has a simple answer but I just don't understand what exactly is causing this error. Is it the statement? Is it cause the connection fails? How do I solve whatever makes my code fail?

Thank you

Was it helpful?

Solution

Another instance of Derby may have already booted the database C:\temp\database\test01.

With an embedded database, only the application that it is embedded in can access it. Check to make sure that your previous application is fully stopped. The simplest solution for that is to just restart your operating system, but if you are familiar with killing processes, you can look for all your java processes and kill them.

Another thing I have seen sometimes is somebody copying the files from a Derby database to another location, while that Derby database was being used. This leaves the copy of the database in a locked state. That's likely not your problem though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top