tags:

views:

65

answers:

1

I was trying to connect to a hsql db.. I created one by running from C:\myhsql

java -cp .;C:\hsql\lib\hsqldb.jar org.hsqldb.Server -database.0 file:db\mydb -dbname.0 MYDB

This created mydb in a directory called db,This folder now has a .lck,tmp,script,properties files with name mydb And similar files with name MYDB in current folder .

In java code I tried Class.forName("org.hsqldb.jdbcDriver"); connection = DriverManager.getConnection("jdbc:hsqldb:file:db/sjdb", "SA", "");

When I run the program ,I am getting this error,

java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@f3811c1a[file =C:\myhsql\db\mydb.lc k, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2010-10-19 12:46:09 heartbeat - read: -6750 ms. ...

I have pasted the stack trace here http://pastebin.com/mDd8ceqG

Can somebody tell me what I am doing wrong? .I can connect to the db using SwingDBManager and can insert,delete&select records in the db.I was not running DBManager when I tried the java code.Still the lock problem happens.

regards&thanks

mark

A: 

The first command starts a server. This server locks the database files so that "others" cannot modify them. You should use "-dbname.0 mydb" instead of "MYDB" as it should be in lowercase.

Your Java connection URL to connect to the database is wrong. You should use "jdbc:hsqldb:hsql://localhost/mydb" as the connection string. While the database files are locked by the server, you can access the database server but you cannot access the database "in-process" with a file: URL.

fredt
thanx fredt for the help..
markjason72