Apache Derby DB not working when I close NetBeans

2019-10-04 01:51发布


I am a beginner to Java and Databases.
Recently, i have been developing a Java Application where I am using derby database. When I start NetBeans and run the project it works fine. But when I close the IDE and run the .JAR file it does not not work. Can anybody tell me the reason behind it?

2条回答
神经病院院长
2楼-- · 2019-10-04 02:18

Obviously it will not run as when you connect to the localhost:1527 port, it opens in Network mode (more exactly a client-server mode) which means : it will only work when the IDE is running which runs the Apache Derby DB Server and all other services.

You should try running it in Embedded Mode which will run your database even if you are not establishing a connection to the Derby server.

In a more simpler way I would say that it acts just like a file to your java executable, which manipulates data based on the schema you provide. You must try this fantastic and simple way Java, NetBeans and Derby Embedded. It will server your purpose. But before you begin Embedded you must add derby.jar file to your classpath.

Thanks!! Hope it helps

查看更多
ら.Afraid
3楼-- · 2019-10-04 02:24

Netbeans is running Apache Derby for you in a networked mode, and your application is connecting to it. When netbeans is not running, then the database is not running either, so it's not available to your application.

If you want your application to run w/o a being able to reach a database over a network, your application must be changed to run Derby in embedded mode.

If you want your application to run connected to a networked version of Derby, you will need to arrange to run Derby somewhere that your application can connect to it.

查看更多
登录 后发表回答