variable « JDBC « Java Database Q&A

1. Using a variable instead of a parameter index with a JDBC prepared statement

In many programming languages something like this is possible for prepared statements:

PreparedStatement statement = connection.prepareStatement(
    "SELECT id FROM Company WHERE name LIKE ${name}");
statement.setString("name", "IBM");
But not with java.sql.PreparedStatement. In ...

2. Prepared statement - static variable

I think what you are looking for is caching of prepared statements. Some connection pools do that for you as an optional tuning parameter (Weblogic, I think JBoss too). Handy for situations where the same prepared statement will get used multiple times in a runtime session, not necessarily even in the same transaction. Your use of a static basically means you ...