How to embed database derby in jar file - java

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.

Related

How can I allow other computers to access my programm's database?

I have a java application that I programmed, and I also created a Wampserver database to store the app's data. When I install the application in another computer, it basically can't do anything because wampserver isn't installed on that computer, and even if it was, the database wouldn't be imported on that same computer.
Can I install the database with the program itself, without making a database server in my computer? (For security reasons)
Sorry if this is a dumb question, im new to programming.
Assuming you are doing this in a Home/office environment. Where your IP Addresses do not change so often. Or you have the power to assign them statically.
You could try using a multi-threaded client server model. Where your wampserver computer(server) will accept a connection from another computer(client), and from there any queries to the database will be handled by that thread. This way, you could get away without installing wampserver on every client.
It would require some networking codes to be added to your java program. There are many examples on multi-threaded client server model -> Multithreading with client server program
You can open your MySQL server to the outside world or to certain IP (comment or edit bind value in your MySQL configuration file).
This can be a security issue. What is your objective? Usually, you'd do an API allowing access to your data from your application.
You are talking about "hosting" your database. You need to either:
Create, develop, and run a hosting service (not trivial), or
Pay to one the myriad of hosting services available, and install your database there (cheap these days). Just a couple of well known examples: Digital Ocean or Amazon Web Services.
In any case, it's a huge security risk to open your database to any client online.
Normally you write a program/application that accesses the database in the same [local] network, and that application serves web pages (or other web service) to the world.

Apache Derby DB not working when I close NetBeans IDE

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

Derby java -derbyrun.jar server to change embedded mode to server mode

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.

Connecting Access Databases remotely?

Currently I have a Java application which performs all I wanted and the limitation
in it is "It only resides on the Local machine for which it needs to work". I have the Access Databases located on a Remote Server and I install the Java app on the remote server to connect the databases using a connection string jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\\DATA\\DPPI\\DATA\\DPPI\\DPPIPR01.mdb;
It connects to Access Databases and do all the business logic with them.
Enhancements (to be done):
Making the application online - not a big issue.
Connecting the databases remotely - its the only concern.
If I make the Application Online the Access Databases need to be connecting through network (somewhat like IP or some web address).
Problem:
But after going through this Connect to Access database remotely It seems my requirement can not be completed.
Is there any way if I'm able to upload the database to the online web hosting server and access the database from there only? If yes, then how should I do the connectivity since Access Database connects by giving the fully qualified name containing drive letter and all.
But how should I proceed further so that I may be able to connect the mdb Databases remotely?
ADO Solution:
But after going through the link: http://webcheatsheet.com/ASP/access_connection_strings.php, it seems we can perform remote Access Database connectivity.
The solution for the ADO is something like:
connectionString="Provider=MS Remote; Remote Server=http://your_remote_server_ip;" &_
"Remote Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\your_database_name.mdb"
I'm a tad confused to how Access Database we can connect.
There is one more question in my head.
I'm making use of Type-1 Driver. Should the Type-4 Driver support the remote connectivity?
If your application is a server side application (like a web application) and your server's OS is Windows then theoretically it is possible to use your Access database. In this scenario, the Access database is local to your application. In your connection string you can simply use the path to the Access database inside your server's file system.
But keep in mind, that Access is a desktop database not made to use it as a server database. This can lead to poor performance and maybe system crashes. And it is possible that there are some licencing issues for this use case.
So even it may be possible to use Access with a server application it is strongly recommended to use a real server database like MySQL, MS SQL Server, etc. Even an embedded database like Apache Derby or H2 would be a better fit.
If your application runs at client side like a fat client, then your only chance to use Access is to put it on a network filesystem, so it is visible from every client. But this works only inside a LAN. If you cannot put it on a network filesystem then you have to use a real server database.
Do not use Provider=MS Remote (RDS) for new development. Here is a quote from the MSDN article
Microsoft OLE DB Remoting Provider (ADO Service Provider)
Important
Beginning with Windows 8 and Windows Server 2012, RDS server components are no longer included in the Windows operating system (see Windows 8 and Windows Server 2012 Compatibility Cookbook for more detail). RDS client components will be removed in a future version of Windows. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Applications that use RDS should migrate to WCF Data Service.
As others have suggested, you should seriously consider using a different back-end database for this particular application.
What if I'm able to call another java application residing on the Server housing the Microsoft Access Databases? Can you please let me know if it can be the solution such that I will have the division of my application into two:
1. The Online java Application performing 2 things: Accepting the requests coming in and waiting for the response to come from another application running on the Server housing the Microsoft Access Databases.
2. The Java application installed on the Server housing the Microsoft Access Databases only responsible for connecting and returning the DTO (Data Transfer Objects) -or some kind of objects in Collections.
So, I would expect a serverside program to handle the communication with the DB and the client application would communicate with the server app.
Please let me know if I should proceed in this manner.
it can be done by marking the traffic and queueing the traffic from the server---to----remote site ---(QOS..quality of service ) .....the two sites will be connected through VPN methods to reduce the unnecessary hops that will improve the latency plus add the security , thus server and remote site will logically act as if they are on the same network (LAN)
regards ,
Ali Rehan

How do you start derby in network server mode and still get an embedded connection?

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.

Categories

Resources