I have 15 prepared statements that I will use very often throughout the application. Some of them will be called several million times during one task.
I decided to use prepared statements, as parsing a regular statement a million times does not seem like a good idea.
I plan to create a utility class that will manage all things related to the database and all trained operators. The statements will be stored as static members, which I can call by passing the appropriate arguments.
Are there any problems with storing prepared statements as static elements that I should be aware of?
I use sqlite-jdbc if that matters.
EDIT:
Here's how I plan to manage my prepared statements
class DBUtils {
private static PreparedStatement psInsertPerson;
public static void createStatements() {
psInsertPerson = conn.prepareStatement( ... );
}
public static void insertPerson( ... ) {
psInsertPerson.set...
psInsert.addBatch();
}
}
source
share