TransparentPreparedStatement

This free class provides transparency into your prepared statements by letting you see "into them" and see what the SQL statement that is going to be executed looks like.

To use this class, simply include it in your classpath and replace the parts of your existing code that creates prepared statements with a call to the static prepareStatement method of the TransparentPreparedStatement class.

e.g. replace the following:


        Connection conn = ...;
        PreparedStatement stmt = conn.prepareStatement(
            "INSERT INTO foo VALUES (?, ?, ?)");

    

with this:


        Connection conn = ...;
        PreparedStatement stmt = 
            TransparentPreparedStatement.prepareStatement(conn, 
                "INSERT INTO foo VALUES (?, ?, ?)");

    

Now you can call the .getQuery() method to see (roughly) what the actual query being executed looks like. (Especially useful is the ability to evaluate a call to the getQuery() method in the display panel of your favorite debugger (e.g. Eclipse)).

The code currently only handles the major types of setters -- Strings and numeric types. The statement it shows may be more correct for some brands of databases than others.

Improvements will be made based on our own usage of the class as well as any feedback we receive. If you would like a feature implemented or a new data type supported, send e-mail to freesoftware@jpevans.com with the details and we'll see what we can do. Or, even better, submit a patch with the new feature or data type. :)

NOTE -- This .zip file includes everything you need to build AND run the unit tests for the TransparentPreparedStatement class. This includes the hsqldb database. See the file lib/hsqldb_lic.txt for licensing information. All of the extra files included are just to help you build and run the unit tests. The ONLY file that needs to be deployed with your application is the binary class file (which can be found in the bin sub directory).

Building

I use Eclipse for building it, and my Eclipse project, classpath and jardesc files are included in the source release, however it's pretty simple to build and if you really want to build it from scratch I'm sure you already know how. If you really need more help with it, e-mail me.

What's new?

  • Aug 17, 2004: Version 1.0.0 released (initial release).

License

This software is made freely available under the MIT License.

Downloads