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\\m
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();
}
}
}
}