I have a Java Applet which displays 2D table data from a Derby database. I am also using Netbeans. I want this application on a webpage. I have uploaded the html document and all the .class files into the proper directory on the server. What remains is accessing the database.
I would like to use Embedded Derby so that my application contains the database (is my understanding of that fact correct?). Then I should be able to upload the html and jar/class files to the server and my application will be deployed. However I am confused on the following:
How do I create/setup the database to live on the webpage?
What would my connection string be?
Is there a better way to do this altogether in NetBeans?
All help is greatly appreciated. Let me know if I can make my question clearer.
You can package your Derby database itself inside a JAR file as part of your applet, and then it will be effectively part of your applet and downloaded when your applet is downloaded.
See this related question: Distribute a database made with JavaDB with Java program
Note that this will create a read-only database. If you actually need to update your database from your applet, you'll need a more sophisticated approach (e.g., package the initial data into the applet, then when the applet starts up, request access to local storage on the workstation and create the writeable database there).
For complete documentation on building and deploying a database-in-a-jar, the documentation is here: http://db.apache.org/derby/docs/10.9/devguide/cdevdeploy15325.html
Related
I have written an JavaFX application to study German language with a Flashcard like program. It turned out my classmate also want this but I don't know how to deploy it.
I have a sqlite database which store some german words and I need read/write access. I have tried hardcode the path but it obviously is not good. I have tried to load the sqlite file by the following line and deploy it as a runnable jar but I couldn't write on it.
"jdbc:sqlite::resource:Vokabeln.sqlite"
Assume that I don't want to make remote web application, how should I make this file available to my code, and is platform independent? Should I make a installer program so that I ask the user what is the path? I also don't know how to write an installer application. I googled and didn't find anything like that.
You'll want to distribute your application with the database as a file outside of the Jar because otherwise you won't be able to have write access to it.
If the database file is on the same directory/folder as the Jar file, you should be able to connect to it with a JDBC URL like the following: jdbc:sqlite:sample.db
Distributing your application as a Zip file is fine, but if you can't expect end users to have Java installed and so, there are programs to create installers, even cross-platform, such as IzPack and Install4J
I have developed a movie organizer program in Java with derby database. It works fine on my computer, however I couldn't figure out how to make it "portable" (only for my own use).
My problem is, that if I use the
String url = "jdbc:derby://localhost/Movie";
code for the connection to the derby database, it is only working on my computer as it is the path specified directly to my Netbeans database location. I would like to put the Movie folder near the .jar file of the application and make it portable so I can use the same database everywhere.
Any help would be appreciated on how could I achieve this.
You can access the database from the filesystem for example like this:
jdbc:derby:./myDatabaseName
I am trying for a while to make executable JAVA application having embedded DB (derby DB), but facing some problems, and need your valuable help.
Namely, I am using Eclipse as environment.
I export Java app to RUNNABLE JAR file, and it works fine on my desktop machine.
The idea is to make EXE doubleclick icon and send it to another machine which have no JAVA background/environment....so point is to send it to another user who will just get exe file, double click it and work with it.
The DB is not only readable, since application is inserting data in tables.
So, it works fine on my machine, but when I send the same JAR file to another machine, I get error:
"Schema TEST does not exist"
I can see application but without any data, like there is no connection with DB. So, it is useless.
Even I use JSmooth, Install4j.... to convert JAR to exe file, I get the same error.
So, first I have to make JAR file working on another machine.
Seems to me, I am doing something wrong with DB files.
Please let me know what info u need more from my side, and let me know how I can do this.
If the application intends to read AND WRITE data when it is running, then it can't be entirely contained in a JAR file, because you can't put an updatable Derby database in a JAR file. You'll need to have some "installation procedure", perhaps some logic that you run the first time your application is double-clicked by the user, that (a) finds a suitable location for the Derby database on the user's machine, (b) creates the database and defines all the tables, views, etc, (c) loads any initial data.
Then, on subsequent runs of the application, it will be able to re-open the database and continue using it.
I have to create a java applet that needs to access static data which is around 600k in size. This data is exported from an sql database. What is the the best format for that data to be stored in (xml, json, java include file), to get fastest/easiest access to it. I am a complete java noob and this question might be stupid, but is there a way to 'compile' this data in to executable so there are no additional requests to server once the applet is loaded. Thanks in advance!
I do not know what do you mean when you mention 'java include file'.
All the rest is OK. You can use either XML or JSON. It depends on your needs and taste. Just remember that JDK has built-in tools to parse XML and does not have such tools for JSON, so you will have to add external dependency (e.g. GSON). Generally it is not a problem but sometimes code size may be important for applets that are expected to be downloaded from server to client.
The other problems with applets is that unsigned applet cannot write to client's disk. So, whatever format you choose you have to store the information somewhere. You can store it on server, but server has access to DB anyway, so why to create copy?
So, my suggestion is the following. Store data in database. Create server side component (web service) that allows your applet to access the data. Applet should store in browser cookies user id, so next time user runs the applet it enters automatically.
To access browser cookie from applet user live connect and remember that applet tag should have MAYSCRIPT attribute.
If the data is static, just copy in the source tree next to your .java files.
From there, you can access it (from a class in the same package) with:
getClass().getClassLoader().getResourceAsStream("name");
i have a java based web application, i have the source code as well as the war file, the application uses mySql and need some web server like tomcat all to be added to some package that can be directly installed on window and linux machines directly..
i need to setup DB, WebServer, and app in one go. Would be great if it can create services for all as well.
is it possible???
i mean the user should just give the location to store and everything should get stored in one go, is it feasible? and if yes please guide me how to do so...
In short: Yes, it is.
Projects like XAMPP are already following that approach. All relevant software components are inside a single ZIP file which you can extract to an arbitrary location on the user's harddisk. All configuration then uses relative paths when referencing files.
So essentially, you will have to put in a little effort in advance to make the "installation" as easy as possible. Maybe you can simply build upon a project like XAMPP and use the infrastructure already provided?