Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

connection persistence for prepared statements (2 replies)

$
0
0
Hi,

I'm having trouble figuring out whether and how to use prepared statements for a system using java servlets with JDBC. Some of my queries join numerous tables so I would think that prepared statements would help a lot. However, I'm confused about costs and benefits and don't want to add complexity to the system for nothing.

1. If I prepare a query including question marks each time with a different connection from my pool, will this help performance? I have read some posts suggesting that either Java or MySql caches query optimization plans keyed by the query.

2. Alternatively, if I keep a connection associated with each prepared query, will I run into timing conflicts as multiple servlets try to execute the prepared statement at the same time?

The situation seems to be fairly confusing because Java/JDBC "emulates" prepared statements, while there are tradeoffs within MySql such as loss of caching of query results when using prepared statements. So I would also appreciate a pointer to an overall discussion of whether and how to use prepared statements with Java/JDBC and MySql.

Thanks,
Peter

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>