Java JDBC ignores setFetchSize?

Try turning auto-commit off: // make sure autocommit is off connection.setAutoCommit(false); st = connection.createStatement(); st.setFetchSize(1000); System.out.println(“start query “); rs = st.executeQuery(queryString); System.out.println(“done query”); Reference

How to Correctly Close Resources

I think the best answer has already being mentioned, but I thought it could be interesing to mention that you could consider the new JDK 7 feature of autoclosable resources. try{ try(Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost/hrdb”, “obiwan”, “kenobi”); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(“select name from department”)) { while(rs.next()){ System.out.println(rs.getString(“name”)); } } }catch(SQLException e){ … Read more

How can I abort a running JDBC transaction?

As mentioned by james, Statement.cancel() will cancel the execution of a running Statement (select, update, etc). The JDBC docs specifically say that Statement.cancel() is safe to run from another thread and even suggests the usage of calling it in a timeout thread. After canceling the statement, you’re still stuck with the job of rolling back … Read more

ojdbc14.jar vs. ojdbc6.jar

The “14” and “6” in those driver names refer to the JVM they were written for. If you’re still using JDK 1.4 I’d say you have a serious problem and need to upgrade. JDK 1.4 is long past its useful support life. It didn’t even have generics! JDK 6 u21 is the current production standard … Read more

How to avoid storing passwords in the clear for tomcat’s server.xml Resource definition of a DataSource?

As said before encrypting passwords is just moving the problem somewhere else. Anyway, it’s quite simple. Just write a class with static fields for your secret key and so on, and static methods to encrypt, decrypt your passwords. Encrypt your password in Tomcat’s configuration file (server.xml or yourapp.xml…) using this class. And to decrypt the … Read more