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?
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.
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
Related
I'm using a derby db in my JavaFX app, everything works fine, but when I connect to my db in netbeans to check out some records, and then start my app again, I get this error:
Another instance of Derby may have already booted the database
I disconnect from the db but I still get the exception, it is resolved when I restart my pc.
How can I resolve this?
In embedded mode only one process is allowed to access the Derby database files. If you open the database with netbeans to see what's going on, then your JavaFX application would be the second process accessing the database files in embedded mode. But the files are still open in netbeans.
During development it is often necessary to view the database contents at the same time your application accesses the database. You can start a Derby Network Server and access the database in client mode instead embedded. Be sure to switch the connection strings for both netbeans and your JavaFX application.
When you deploy your application you can easily switch back to embedded mode by changing the connection string in your configuration.
I do not want to install a database server on target machine. It is possible that we can simply ship a jar file with the database embedded in it, and not worry about installing a database server separately?
I created one application in netbeans using derby and it is working fine in my pc but when i am running on other machine it is giving me Error connecting to server localhost on port 1527 --> this error says that there is no Database running on port 1527. but i dont want that the client should take more efforts to start DB server and all technical process. It should be simply runnable when i start application Derby DB should start and when i close DB should close.
So what will be the solution for my problem?
And one more Question is Can i use derby database for large scale projects?
No, you don't have to install a database server on the target machine; Derby works just fine in embedded mode without a separate server.
However, if you want multiple client applications to be actively sharing the same data in the same database, you'll want to use the client-server mode, not the embedded mode.
And yes you can embed a jar with the database into your program. If you want to know how, read this documentation: http://db.apache.org/derby/docs/10.11/devguide/cdevdvlp24155.html
And yes you can use Derby for large scale projects. But it doesn't come with all the enterprise features (online backup, etc.) that a true enterprise scale commercial DBMS comes with.
But, since it sounds like you are just getting started with Derby, can I suggest that you please start with the Derby tutorials before you try these advanced configurations? Here is the link to the Derby tutorials: http://db.apache.org/derby/docs/10.11/getstart/
It may not be possible to give you very good advice without knowing a lot more about the application you're trying to build and the overall architecture you're trying to use.
I have derby DB working fine in embedded mode through my netbeans IDE as am
developing accounting multi-user systems ,it's my first time with Derby and understood later embedded
mode not allowing multi users/pcs, only single user, so i decided to move my Derby
into server mode and am trying for days changing environment variable to convert to server mode ,and change my embeded one into server one is possible or i have to drop the derby and install server mode ,now am attempting to run derbyrun.jar from my Linux terminal but i have got below error message .
wso here i can put the jar file to avoid seen below error :
java -jar derbyrun.jar server start
Error: Unable to access jarfile derbyrun.jar
any help will be great
It sounds like derbyrun.jar is not in your classpath.
I suggest you take a couple hours and work through the Derby Getting Started guide here: http://db.apache.org/derby/docs/10.11/getstart/
In particular, there is an example in that manual of taking a Derby application which runs with the embedded driver, and converting that application to use the client driver: http://db.apache.org/derby/docs/10.11/getstart/twwdactivity4.html
In general, all you have to do is to change your connection URL, include derbyclient.jar in your classpath, and have a running Derby Network Server that is providing access to your database.
To run the Derby Network Server, you should start with the startup scripts that are provided in the Derby distribution; this, too, is covered in the Getting Started guide.
If a java desktop application from a client machine needs to connect to a database on an external central server (on another machine), kind of like a php script that can connect from a browser on the client machine to a database, how would that be accomplished? I know that you can use JDBC, but wouldn't the person who's running the desktop application need mysql connector/j driver installed on his/her computer?
As long as you bundle the appropriate JDBC driver (usually a jar) with the application and make sure it's on the runtime classpath everything should work. There is no "installation" of the driver separate from having the appropriate classes on the application's classpath.
Of course: if an application is using JDBC to connect to a DB they'll need the appropriate JDBC driver.
Most applications already have a set of library dependencies; it would just be another one.
I just want to know how I can start derby in network server mode and still be able to get an embedded connection?
Thank you.
You need to launch Derby in "embedded server mode". If you are already using Derby in embedded mode, this can be enabled by providing the necessary files in your classpath, then specifying a handful of command line arguments when launching the application.
First make sure the following jars are in your application's runtime classpath.
derby.jar derbynet.jar
Then add the following command line options to the Java command used to launch your application. If the class files are missing, these options will have no effect.
-Dderby.drda.startNetworkServer=true
-Dderby.drda.portNumber=8011
I'm running Derby from within a servlet hosted by Tomcat, so I added these options to the catalina.bat file.
Start up your application and check the list of open network sockets.
netstat -an | find "8011"
You should now see Derby listening for connections on 8011. Its now possible to connect to the database using Derby's client driver (derbyclient.jar). The instructions at http://docs.oracle.com/javadb/10.3.3.0/adminguide/radminembeddedserverex.html cover this part pretty well.
It was hinted that running Derby in this mode may be discouraged. I don't believe that to be the case. Your application will continue to access the database using the embedded driver, while other software is now permitted access using the client driver.
The Embedded Server mode sounds like what you are asking for. It allows you to start a network server when you start the embedded database.
It sounds contradictory that you want to start derby in network server mode and get the embedded driver. Even if this might be possible, it is definitely discouraged. You should decide on whether you want to use Apache Derby in the network mode using the DRDA or as an embedded driver and stick to that decision.
Here you'll find a tutorial on how to use the network driver:
http://db.apache.org/derby/papers/DerbyTut/ns_intro.html
Some one correct me if i am wrong, Both will run on separte ports. So you can connect to the required one using the proper connectionName, right?
#pawelocue: Sorry, but this is wrong. Using the embedded server mode is perfectly alright and sometimes very useful. It is definitely not discouraged.