Ways to Actively Update Java from MySQL - java

What is the best way to update a Java or GWT program from MySQL. For example, a MySQL database which holds Weather information... updating whenever the weather changes a degree. How would I update a Java / GWT field with each update. Would I use a thread to query every few seconds??

Certainly you can do polling.
Alternately, you could use a trigger to trigger a stored procedure that then sends a message to your running Java program. This would probably require that you write a C++ function to install in your MySQL installation as a custom procedure. Apparently (and this is cool) it's possible to do that on-the-fly without even stopping the server, via the plug-in API.
Edit A third option that really should have been at the top of my original answer: If there's any way to channel the updates to the DB through the business logic layer (!), that would probably be the best way to go. If the update absolutely has to come from somewhere other than your Java program, pehaps it could notify your Java program in addition to updating the database?

Related

How to Store Data Without a File or Server in Java?

So, forgive me if I'm too ambitious and this isn't possible, but I am wondering if it's possible to like set a variable while my program is running, have it closed, have the computer shutdown, and have the app start up again, and have that variable the same as it was.
I've only ever heard of people using servers or files, and so I'm wondering if this is possible.
It is not possible to store a variable forever in side your application. You'll have to either store in the HDD or send a web request to a server where they store values for you.
Build your own website using PHP. There are many free web hosting services. Host your website and your database. Send a HTTP request and you may write a JSON response from your server side.
If that's a lot of trouble, file saving method would be the easiest.
You'll need to write the state of your application out to disk somehow, there's no way around that. Note though this doesn't necessarily have to be a disk on the same machine that your app is running on.
Usually this is accomplished (in the Java land) by using a dB (mysql for instance), then using either plain JDBC to fire off SQL queries, or using an ORM such as hibernate (which will then use SQL underneath.)
You can use something called object serialisation to save the state of your objects to disk directly, and then recall them later. However, this is generally considered an ill advised, obsolete approach (and Oracle are planning to remove it entirely in a future version of Java, so definitely one to stay away from.)

Calling Java Application from Postgres Database trigger

I am trying to execute my java application once a record is inserted, deleted or update into a database table. For that sake, I am planning to write a Trigger which will be called while inserting. My question is that, will I be able to call a java application from this trigger?
While Python and Perl, among others, have a PL equivalent that can be written within an SQL function (albeit with sometimes considerable overhead), Java does not. Even if the Java app could be launched via command line or something after a trigger, the overhead in launching the JVM alone would be a performance disaster.
I would recommend looking into having Postgres emit notifications via notify. This would let you send a payload (although there are size limitations) that can be listened for by a client (that client could be your Java app, or an intermediate program that performed some additional ETL to get it ready for your app). This should allow for the data to be served up and processed in a performant way.

Alternatives to SQLite for Java that supports multi-user write

Does anyone know of a sqlite alternative for Java that would support multiple write(s) at the same time?
I'm aware of the option of checking to see if the database is available and pause the attempt to write until it can actually write. But still I'm looking for alternatives where I can really do concurrent writes.
Update (further explanation):
I'm setting up a system where there will be multiple users keying in a single database so I would naturally like the idea of being able to work non-stop instead of having to pause to wait for the database to be available for writing.
Take a look at H2 - it's feature rich embeddable file-based DB.

Oracle call to Java method on another machine

I am not allowed to compile the java class into the instance of Oracle we're running on, per architects request, so I am looking for alternatives. The requirement is to utilize a java library located on an application server on the network. Is it possible to call a java method located on another machine from PL/SQL? I found this article talking about external procedures in Oracle, but I'm not sure that it allows for this. As a side not, the performance would also have to be fast enough to be used in batch processing of thousands or millions of calls.
I suspect the best you can do is add entries to another table which your Java process polls to get each or batches of messages. Oracle is not really designed for message processing.
In any case, I would discuss this with your Architect what to do as he is the expert. ;)
If your Oracle system can't do the job, you may need to have a solution which doesn't use Oracle.
You have three options:
1.) We solved a similar problem by making PL/SQL call HTTP using UTL_HTTP and then let the app-server call the java procedure. We did this to interface our Oracle Database with Oracle Reports. The PL/SQL fired an HTTP Request which was received by the app-server which called Java. The Java can call back PL/SQL via normal JDBC.
2.) You might not be able to load that java proc, but maybe you can create some other java stored procedure that can invoke it using RMI.
3.) AQ is another method. Basically you can Queue a message using AQ and use JMS on the App Server to Dequeue it and use it.
Option 3 would be the fastest, though we have tried option 1 and the latency for this is not as much as you might it. It also offers a way to do some parallel processing by running multiple requests in parallel.

multi mySQL driven web site

I have database driven web site that needs more than one MySQL Sever to handle the expected demand
I also need to implement back up system (of some type) to keep data safe.
I'm using java but that that’s not critical
What options are available to me from projects out their
I'm thinking of daisy chaining project with the MYSQL server's somehow and then when one is busy go to the next and they all be written data to. I know they can measure time used they must be able to measure when they are in use.
You might want to look into clustering.
http://www.mysql.com/products/cluster/
How about deploying a Cluster in the cloud?
http://www.mysqlconf.com/mysql2009/public/schedule/detail/6912

Categories