Hi all,
i have a lack of understand how it works. I Hope someone can explain it.
Let us start with Prepared Statements first. I think all of you know them. To achieve performance gain they have to let open, just passing new parameters.So the first time i use them i have to create it from a SQL-Connection.
PreparedStatement pstmt = con.prepareStatement("SELECT * from foo where id=?")
For reusing i usually would cache or save them in my application. I dont close them.
The Specification of DBCP said, they support PreparedStatements in pooled Connections.
Really Nice. But, Uuhm? How it works?
In my application i can call a Connection from the Pool and release them with closing it.
Unfortunatly my PreparedStatement depends on the connection and will released too. Right?
Connection con = DataSourceX.getConnection();
PreparedStatement pstmt = con.prepareStatement("");
con.close;
//Next Call of the Connection:
con = DataSourceX.getConnection();
//what now?
pstmt = con.prepareStatement("")
I assume this code will create a new PreparedStatement. The advantage of performance and recycling would be gone, until i doesn't know how to access the previous prepared Statement?
The Documentation on DBCP or GOOGLE haven't help me. I hope you can. :-)
Thanks a lot!