I am developing a web application using tomcat server. Database is MySQL. I use connection pool for databse access. The problem here is I am taking read only connection at some occassions but after closing (releasing) it and if i take another connection is is also read only. Connection readOnlyCon = DB.getConnection(); readOnlyCon .setReadonly(true) ................................ readOnlyCon.close(); Connection Con = DB.getConnection(); Here this connection some times returns readOnly connection. Otherwise we need to explicitly set this as readOnly(false); Is this is a problem of Java or Tomcat ?
(In reply to comment #0) > Is this is a problem of Java or Tomcat ? Neither - I would say it's a DBCP problem. However, Tomcat distributes its own refactored version of DBCP, so perhaps someone here needs to check this out? A self-contained test case would be useful..
This is expected behaviour IMHO. You are changing the connection from the default state and then returning it to the pool without reverting your modifictions. This violates the principle of least surprise. DBCP does not alter read-only status of a connection when it is returned to the pool. If you set a conn to R/O and then return it to the pool (conn.close()) without doing conn.setReadOnly(false) it will retain it's R/O status. The next consumer of that connection will get it with R/O set.
Is this was to be fixed, and it is debateable whether it is an issue or not then it would need to be fixed in DBCP. Regardless, this is not a Tomcat issue.