Monday, June 13, 2011

problem while using dbcp with oracle database

We have two different databases in a project; an Oracle and a MySql one. Both of them need connection pooling for a better performance. First, I add dbcp context for mysql to my application context. The settings were quite straightforward. But when I try to use the same settings (except for the connection url and the driver class name of course) for the Oracle data source I got the following exception:

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-00923: FROM keyword not found where expected

which can be translated as "there's some FROM statement missing somewhere while setting your connection". My validation query for MySql was just "SELECT 1" which annoys Oracle database. I change it to "SELECT 1 FROM DUAL" and it's fixed.

Tuesday, June 7, 2011

three screens in vlc media player while playing wmv

If you're trying to watch a video of Windows Media Video (WMV) format with vlc player but vlc is opening three windows of the video in the same time let me give you a hand. First open Video - Video Track from the menu and then select disable and then track 1. One window is better than three for a movie, right?

Monday, May 30, 2011

EmptyResultDataAccessException in your face

Recently I get an EmptyResultDataAccessException in a project where we use Spring JDBC. The full exception listing is "org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0". When I trace the exception I see that I'm calling queryForLong() method of JdbcTemplate for "SELECT Column FROM TABLENAME" on an empty table. Column here is of Long type. Now, I plan to catch the exception and return an unusual value (like -1) as a result. On the service layer, I plan to check for equality to the unusual value and proceed with the right logical flow.

Notice that if you use some function like count(), min(), max() ... in the same query (SELECT MAX(Column) FROM TABLENAME) you won't get the same exception but a "0" result instead.

Wednesday, May 11, 2011

a great way of improving your java code: findbugs!

We decided to make our project's code more robust and bug-free. I suggested the use of Findbugs which is basically a program that uses static analysis to search for bugs in your java code. It can be used as IDE plug-in or as a stand-alone application. Findbugs pinpoints problematic places in your code. There are many type of pre-defined problems that Findbugs looks for like duplicate case branches in switch statements, streams which are not closed in all cases, inefficient use of map iterator, redundant comparison to null ... etc. I can't recommend Findbugs enough.

Tuesday, February 22, 2011

bufferedwriter or windows, which one of you is my enemy?

I was planning to name a file I generated using the username and the date of generation, so my naming format was like "01-03-2010-13:33-user1". When I'm trying to do that with BufferedWriter of our beloved Java, this file is not created. ":" is not allowed by Windows so a file with "01-03-2010-13" as a name is created and nothing is inserted although I called bufferedWriter.write("something"). The good part is that no exception is thrown by BufferedWriter. Great isnt it?