HSQLdb server creation problem

I have rattled my brain on this now for a few days. i have searched hi and low, and cant find an example on creating a server for the Data base HSQLdb,

there is the code that i am using, the problem is it always returns as the discriptor "shutdown" and i dont know what i am doing wrong,

thus NO client can connect to it,

publicvoid setUp ()

{

try

{

Class.forName ("org.hsqldb.jdbcDriver");

// Connection c = DriverManager.getConnection (urlr, user, password);

}

catch (Exception e)

{

e.printStackTrace ();

}

String db_name ="mydb";

String serverProps;

String url ="jdbc:hsqldb:file:mydb";

String user="sa";

String password ="";

System.out.println ("network mode");

server =new Server ();

server.setRestartOnShutdown (true);

server.setDatabaseName (0, db_name);

server.setDatabasePath (0, url);

server.setLogWriter (null);

server.setErrWriter (null);

server.start ();

//server.setPort (5000);

//server.start();

System.out.println (server.getStateDescriptor ());

System.out.println (server.getAddress ());

String urlr ="jdbc:hsqldb:hsql://localhost:mydb";

try

{

Class.forName ("org.hsqldb.jdbcDriver");

Connection c = DriverManager.getConnection (urlr, user, password);

}

catch (Exception e)

{

e.printStackTrace ();

}

}

can any one please help me out? with a link to a code on setting up a server? or any thing, i just find lots of code to make the clients (that i can do) but his server thing is just not working.

Thanks

David

[2594 byte] By [Nibura] at [2007-11-27 11:57:47]
# 1

this is where i found an example, as well as some others but i cant seem to get it to work,

just the server, ..... :)

http://forum.java.sun.com/thread.jspa?forumID=48&threadID=701385

Nibura at 2007-7-29 19:15:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

java -classpath hsqldb.jar org.hsqldb.Server

Once again i tried the demo code for server creation, and well it works,

there must be somthing wrong with the way that I am calling the server? or not starting to correctly,

also i would really not like to use the "test" data base, and i would like some other stuff to happen before and after you shut down the server, that is why i need to create it using my own code?

any ideas? I am using netbeans, windows, but that should make a difference because it compiles and finds the lib's,.,,

Nibura at 2007-7-29 19:15:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Take a look at the source code and see how the command line invocation of the server differs. Is there any particular reason you need the server to be running in network-connected mode? If not, you could just use the mem mode which is very straight forward.

dcmintera at 2007-7-29 19:15:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

multiple clients,

also i would like the abilty to like shutdown the server, and then the clients cant access it..

The problem is i have an example code froma downloaded applicaton, and they seem to be using the same code as me, the only difference is i am launching mine from netbeans, OR the .jar file, and theirs had all the .class files with a .bat script.

Thanks.

can any one else try this code and see if they also get the same "shutdown"

import java.sql.Connection;

import java.sql.DriverManager;

import org.hsqldb.*;

/**

*/

public class MyServer

{

int port = 5000;

String db_name = "mydb";

String serverProps;

String url = "jdbc:hsqldb:file:/lib/database/mydb";

String user= "sa";

String password = "";

Connection c = null;

Server server;

public MyServer() {

setUp();

}

protected void setUp() {

try {

Class.forName("org.hsqldb.jdbcDriver");

} catch (Exception e) {

e.printStackTrace();

System.out.println(this + ".setUp() error: " + e.getMessage());

}

server = new Server();

//server.setDatabaseName(0, db_name);

// server.setDatabasePath(0, url);

server.setLogWriter(null);

server.setErrWriter(null);

// server.setPort(port);

server.start();

System.out.println (server.getStateDescriptor ());

}

public static void main(String[] args) {

new MyServer();

}

}

null

Message was edited by:

Nibur

Nibura at 2007-7-29 19:15:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

Copying the server code, from the source seems to work, only i not have NO clue how to change the DB name,

but i am sure i can work that out,

thanks. for the suggestion

Nibura at 2007-7-29 19:15:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

It looks to me like you have to provide it as one of the properties - the main() method implementation takes the argument array and turns it into a HsqlProperties collection. Presumably you could have a look at the server setProperties method to determine what it actually does with them thereafter to set the database name.

dcmintera at 2007-7-29 19:15:57 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...