简体   繁体   English

使用java启动derby db服务器和客户端

[英]start derby db server and client using java

I hav made a java application using Java Swing . 我使用Java Swing制作了一个java应用程序。 It uses derby db for database and host= localhost . 它使用derby db for database和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:- 我可以使用windows中的命令提示符启动数据库并将其连接到我的应用程序。但是为了部署我的应用程序,希望这可以通过我的java程序中的几行帮助自动发生。我尝试在.bat文件中执行命令但是使用它命令提示符的黑色窗口始终保持打开,我不想要。所以我尝试这样做: -

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. 我还尝试使用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. 有人请帮助我通过API或使用Process和RunTime类或一些更好的方法将我的Java应用程序与derby数据库连接。

Perhaps you don't need to run Derby as a Network Server. 也许您不需要将Derby作为网络服务器运行。 Why don't you just use Derby in embedded mode instead? 为什么不在嵌入模式下使用Derby呢? See this section of the documentation for more information: http://db.apache.org/derby/docs/10.9/getstart/cgsquck70629.html 有关更多信息,请参阅文档的此部分: 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. 我试图使用netbeans(JavaDB)的用户界面启动数据库服务器,该界面仅在netbeans IDE中运行,并且不会像在其他组件中那样自动将任何代码放入程序中。 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 . 因此,要在外部环境中启动和停止DB服务器,我必须显式键入http://db.apache.org/derby/docs/10.8/adminguide/tadminconfig814963.html中给出的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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