Database lock acquisition failure and hsqldb

笑着哭i 提交于 2019-12-03 04:41:46

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.

If you have any other client running that connects to your db you need to close that.

I face this error because I wanted to view a currently opened database in another client like IntelliJ database while the server is using the same db

so to make hsql db able to be connected to multiple clients, use

hsqldb.lock_file=false

so the connection url will be like

jdbc:hsqldb:file:./db/myDbInFile;hsqldb.lock_file=false
muthu vel

Whatever way you have tried is correct.

You don't have to start the HSQLDB Server using seperate java command, below line is not required, as it will lock the database. Prevent other process from starting and locking db.

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

just run the jdbc program

java -cp hsqldb.jar  HSQLAccess 

below line

jdbc:hsqldb:file:db/sjdb

will start the database and will give result.

in this way you don't have to start the server seperately, just have to run the program, which will start and stop HSQLDB for you.

import java.sql.*;

public class HSQLAccess {

    public static void main(String args[]) throws Exception
    {
        Connection con = null;
        try
        {
            Class.forName("org.hsqldb.jdbcDriver");         
            con = DriverManager.getConnection("jdbc:hsqldb:file:db/sjdb", "sa","");    

            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM CMDS_WO_MASTER");
            while(rs.next())
            {
                System.out.println(rs.getString(1));
            }

            con.close();

        }
        catch(Exception ex )
        {
            ex.printStackTrace();
        }
        finally
        {
            if(con!=null)
            {
                 con.close();
            }
        }
    }
}

on my Mac, the port for Connector on HTTP changed from 8080 to 8443 on server.xml. and that is what was giving me this error: both HTTP and HTTPS schema were using the same port

try using the following connection url in windows connection = DriverManager.getConnection("jdbc:hsqldb:file:///c:/hsqldb/mydb", "SA", "");

I just closed NetBeans, deleted database.lck and executed the application again. Everything worked fine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!