Web Hosting Talk







View Full Version : JAVA / Database Question


Derrick
03-30-2004, 07:06 PM
Is it possible to save information from a JAVA applet to a MySql database? I do not think this is possible since from my limited JAVA knowledge the applet is on the users machine not on the server. But I guess I will find out.

Taking a course in JAVA and want to get a head start on a project I have been thinking of.

Thanks,
Derrick

Derrick
03-30-2004, 07:12 PM
If there isnt a way to store data with mysql is there any other way to store data from a applet?

Derrick

stdunbar
03-30-2004, 07:21 PM
As a general statement, no, you wouldn't be able to do this. The default applet security model only allows socket connections back to the same host that served it.

One way you could do this is to do an HTTP POST back to something on the server that is setup to handle it (i.e. Servlet, PHP script, etc.)

Applets do not allow you to write a local file either (again, by default) so your only real option for persisting applet data is to write it back to the server somehow. The advantage of the HTTP POST method is that a web page can be written to do the same thing at some point and the backend doesn't care which client it is communicating with.

Derrick
03-30-2004, 07:27 PM
What about a normal JAVA application on a computer, I didn;t necessarily need it to be online. Is there some form of database option for running a stand alone program off of a PC?

Derrick

stdunbar
03-30-2004, 07:48 PM
That is totally different. With a JDBC driver it is very easy for a Java application to store data in a local or remote MySQL (or indeed any vendor) database. I'd read up on JDBC. If you've ever done ODBC programming (and, shudder, I've done more than my share) then you'll get the concepts of JDBC quickly. Even if you haven't JDBC isn't very difficult.

I can post a quick JDBC program if you need an example.

Derrick
03-30-2004, 08:04 PM
Thanks I will look into this more and post if i have more questions so hopefully someone can help me if I get stuck.

Derrick

Burhan
03-31-2004, 03:21 AM
You can also completely get rid of the MySQL part and use something like hsqldb (http://hqsldb.sf.net).

Derrick
03-31-2004, 01:41 PM
Thanks for the info fyrestrtr, I am going to look into it.

Derrick

Derrick
03-31-2004, 01:44 PM
hmm your link does not work and I can't find it on the website itself. Could you double check your link for me. Thank you so much :)

Derrick

stdunbar
04-01-2004, 12:19 PM
I think that fyrestrtr was trying to point you to the HSQL Database - http://hsqldb.sourceforge.net/

cleaver
04-02-2004, 03:21 PM
Local applet or command line application can connect using the JDBC driver. This is the basic way of accessing a database. There's many other variations that build on top of this (RowSets, EJB, Hibernate). Most simple apps would just do a few JDBC calls though.

If you are doing a remote applet, the accepted way to do so would be to connect the applet to a J2EE servlet application over IIOP or HTTP. The applet talks to the server and the server is responsible for the database operations.

javapro
07-30-2004, 03:04 AM
One thing to note about the HyperSonic SQL database is that it won't be nearly as scalable as the MySQL database. If your application does not require large amounts of data or concurrent connections, HSQL would be a much more light-weight choice to use.