db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam McMahon <a...@cs.miami.edu>
Subject Do PreparedStatements with same SQL compile to multiple classes?
Date Sat, 28 Jun 2014 17:58:01 GMT

I have some questions regarding Derby's compilation of PreparedStatements to
Java bytecode, and how/when that byte/code is loaded/unloaded or released
from memory.

We use java verion 1.6.0_31 and derby

We use a custom connection connection pool that does something similar to
the following. I have labeled the lines of pseudo-code so I refer to them
with specific questions.

1. // pool is requested for a connection, if non exists, create a new one.
2. con1 = DriverManager.getConnection()
3. ps1 = con1.prepareStatement(“select * from cities where id=?”)
4. ps1.setInt(1, n)
5. ps1.executeQuery()
6. //continue to use ps1 with different values...
7. // after con1 is idle for a period of time it is closed by the pool.
8. ps1.close and con1.close

9. // new request comes in, and a new connection is created
10. con2 = DriverManager.getConnection()
11. ps2 = con1.prepareStatement(“select * from cities where id=?”)  // same
SQL as above
12. ps2.setInt(1, n)
13. ps2.executeQuery()
14. //continue to use ps2 with different values...
15. // after con2 is idle for a period of time it is closed by the pool.
16. ps2.close and con2.close()

Here my questions with the above scenario:

a) at step [2] and [10], two preparedstatments are created with the same
SQL, but by different connections. When these are compiled, are two separte
java classes created and loaded? Or is only one newly created/compiled class
created and loaded, and then reused since they have the same sql? (even
though they originate from different connections?)

b) Since Prepared Statements are compiled into byte code and loaded, are
they ever unloaded? If the above sequence continues, will the PermGen (or
another memory space) eventually fill up?

View this message in context: http://apache-database.10148.n7.nabble.com/Do-PreparedStatements-with-same-SQL-compile-to-multiple-classes-tp140440.html
Sent from the Apache Derby Developers mailing list archive at Nabble.com.

View raw message