Archive for May, 2008

Applet and Javascript

Friday, May 30th, 2008

So you have an applet and you want to do one or both of the following things:

  1. Run javascript commands from within your applet
  2. Control your applet through javascript

Step 1 Setup the Object Tag:

<object type=”…”>
<param name=”mayscript” value=”true”>
<param name=”scriptable” value=”true”>
</object>

*Note - I did not show the archive, code or other params needed to setup an object as they are dependent on your applet.
*Note - This setup allows for javascript communication in and out of your applet

Step 2 From within the java call some javascript

import javascript.*;
….
JSObject win = JSObject.getWindow(this);
win.eval(”alert(’test’);”);

*Note - To make this work you need to add plugin.jar from within your jdk/lib folder in the project classpath and include it in your deployment (archive = “…, plugin.jar”).

And tada you can call java functions (yes the public ones) from javascript just by referencing the id of the object (dot) the function name. The translation between object types can get a bit tricky if you try to do a map or hash but with strings, ints and the like its pretty straight forward. The primary use for this was in setting up an event and using javascript to trigger it on submission of a form however the possibilites are endless ;-)

Oracle Blob (JDBC) - How to

Tuesday, May 27th, 2008

This morning I needed to insert a file’s contents into a blob on an oracle database so here is the method used to do that (look for a future post on dropping a file into an applet).

/* File Loaded here into a File Object as f */
PreparedStatement ps = conn.prepareStatement(”INSERT INTO TBL VALUES(?, ?)”);
ps.setString(1, f.getName());
FileInputStream fis = new FileInputStream(f);
ps.setBinaryStream(2, fis, fis.available());
ps.execute();
ps.close();

And tada your record will be loaded into the blob.

*** Not Shown ***
Oracle JDBC Connection - This example does not use any framework/connection helper (i.e. Hibernate/EJB)

Closing

Monday, May 26th, 2008

On the way home today from visiting my family over the Memorial Day Holiday I noticed a “for sale” sign in the parking lot of the private school I attended for the 1st eight years of my educated life (k-8).  A bit struck by this I called my family to find out if indeed the school had closed or if I was misunderstanding something.
Sure enough, the school had closed.
Now some kids would rejoice if their school closed; however for some reason this really struck me as a stark reminder that nothing is Permanent.  I had always envisioned that place as one of those forever icons that would live on throughout several generations; I apparently was mistaken.  In a town where very little changes it seems that this particular piece of nostalgia will go down like most and fade into the history of my life.

SCJA

Friday, May 23rd, 2008

As most know I am studying to get my SCJA and making a much bigger deal out of it than it should be.  I have been through all the test prep books several times and am confident with the material however I find some odd aversion to taking the test.  I guess all of us experience fear of failure and more so when we work with the technology every day ;-).  Oh well I am going to purchase my exam ticket tomorrow and then just finally set a date to go take the thing.  Below is the link to find out more about the SCJA if needed.

http://www.sun.com/training/certification/java/scja.xml

Common Hibernate Options (hibernate.cfg.xml)

Tuesday, May 20th, 2008

Below is a pretty standard configuration which appears to work quickly using an oracle database with a datasource defined in an oracle application server.  I will be refining this over the next week as I performance tune the “massive app”.

<property name=”hibernate.dialect”>org.hibernate.dialect.OracleDialect</property>
<property name=”connection.datasource”>jdbc/xxx</property>
<property name=”current_session_context_class”>thread</property>
<property name=”hibernate.transaction.factory_class”>org.hibernate.transaction.JDBCTransactionFactory</property>
<property name=”cache.provider_class”>org.hibernate.cache.NoCacheProvider</property>
<property name=”show_sql”>true</property>
<property name=”hbm2ddl.auto”>none</property>
<property name=”connection.pool_size”>5</property>
<property name=”hibernate.max_fetch_depth”>0</property>
<property name=”hibernate.use_reflection_optimizer”>true</property>
<property name=”use_outer_join”>false</property>