Category Archives: JDBC

JDBC parameter for null timestamps in MySQL

I just came to know that support for timestamps with null values in MySQL JDBC using mysql-connector-java is not default! It throws an exception. However, using zeroDateTimeBehavior parameter with a value of convertToNull in the jdbc url will do the trick.

Leave a comment

Filed under Database, JDBC, MySQL

A good jdbc based database explorer

I wanted to incorporate Derby into one of my projects and instead of using their ij command line tool, I wanted to use a UI to explore the objects and data. For this, I tried searching for a good tool.

I found this link on Oreilly

http://www.oreillynet.com/oracle/os_dir/gui.csp

But finally I settled with executequery

So far it’s been good experience using it. If you are new to jdbc, more can be learned from these jdbc books.

2 Comments

Filed under Database, JDBC

Why jdbc needs a special api to set nulls?

While Hibernate and other persistence frameworks are good, there are times why one wants to stick to the plain jdbc. One pain point with using jdbc is setting the parameters. People use various paradims including stmt.setInteger(i++,value); to keep track of the index. However, with JDK 1.5 supporting varargs, one can write a utility function like

public void update(PreparedStatement pstmt,Object ... vals) {

for(int i=0;i<i++) {
pstmt.setObject(i+1,vals[i]);
}
}

But if one of the values is a null, then the above doesn’t seem to work. One has to explicitly use stmt.setNull(index,type) api. Not sure why setting a bind to null requires specifying the data type.

Leave a comment

Filed under JDBC