简体   繁体   中英

start derby db server and client using java

I hav made a java application using Java Swing . It uses derby db for database and host= localhost . I am able to start database and connect it to my application using command prompt in windows.But to deploy my application want this to happen automatically with the help few lines within my java program.I tried executing commands in a .bat file but with it black window of command prompt always remains open which I don't want.So I tried doing this:-

Process pserver=Runtime.getRuntime().exec("cmd /c set DERBY_HOME=E:\\db-derby-10.9.1.0-bin");

ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Java\\jdk1.6.0_33\\bin\\java", "-jar",  "E:\\db-derby-10.9.1.0-bin\\lib\\derbyrun.jar server start");
pserver= pb.start();

pserver=Runtime.getRuntime().exec("cmd /c set DERBY_INSTALL=E:\\db-derby-10.9.1.0-bin");  

pserver=Runtime.getRuntime().exec("cmd /c start set CLASSPATH=%DERBY_INSTALL%\\lib\\derbyclient.jar;%DERBY_INSTALL%\\lib\\derbytools.jar;. ");

I also tried using API http://db.apache.org/derby/docs/10.0/manuals/admin/hubprnt14.html -NetworkServerControl. I am unable to understand what package to import and which all libraries to include.

Someone please help me connecting my java application with derby database eitherby API or by using Process and RunTime class or some better method.

Perhaps you don't need to run Derby as a Network Server. Why don't you just use Derby in embedded mode instead? See this section of the documentation for more information: http://db.apache.org/derby/docs/10.9/getstart/cgsquck70629.html

I found out what the problem was. I was trying to start the database server using the user interface of netbeans (JavaDB), which works only in netbeans IDE and doesn't put any code in program automatically as it does for other components. So to start and stop the DB serverin an external environment I had to explicitly type the code as given in http://db.apache.org/derby/docs/10.8/adminguide/tadminconfig814963.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM