Monday, February 18, 2008

Oracle JDBC PreparedStatement & setString Issue

I've noticed some interesting behavior with the Oracle JDBC driver (version 10g, ojdbc14.jar).

This interesting "feature" surrounds the behavior of the PreparedStatement. The easiest way to describe the issue is with an example.

Table A has one column, b CHAR(3).

Query, SELECT * FROM A WHERE b = ?

My intended query was SELECT * FROM A WHERE b = ' ', but the Oracle JDBC driver actually was building this query, SELECT * FROM A WHERE b = ''.

The problem is that when calling setString() on the PreparedStatement to populate the ?, the PreparedStatement strips any leading or trailing spaces.

Normally this wouldn't be an issue and the driver would actually be doing me a favor. However, in my case where I was trying to substitute the ' ' space character it was a big problem.

The easiest way I found to get around this behavior was to simply not use a PreparedStatement. By using a normal Statement, I could control how the substitution was processed and allow the proper query to be generated.

Ubuntu 7.10 Disable trackerd

On my Ubuntu 7.10 desktop I have noticed that for long periods of time the CPU will be maxed out. When I investigate further trackerd is always the culprit.

Since this seems to be a common issue, this is what I do to disable trackerd and reclaim wasted CPU cycles.

1.) Right click on the 'Deskbar Applet'. Go to 'Preferences'.
2.) Scroll down in the list till you see, 'Tracker Live Search' & 'Tracker Search'. Make sure both of these are unchecked.
3.) Press the Close button.
4.) Go to 'System' -> 'Preferences' -> 'Sessions'.
5.) Scroll down the list to 'Tracker'. Make sure it is unchecked.
6.) Logout. (if that doesn't work, try rebooting.)

When you log back in to the system, you should no longer have the trackerd process running.

You can check by issuing a 'ps aux | grep trackerd'. Which shouldn't list a running 'trackerd' process.