Saving prepared statements as static elements

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() {
      // assuming a connection has been set up already
      psInsertPerson = conn.prepareStatement( ... );
   }

   public static void insertPerson( ... ) {
      psInsertPerson.set...
      psInsert.addBatch();

      // figure out when to perform batch insertion at some point
   }
}
+3
source share
1 answer

Do not do this with static. Use the Apache DBCP connection pool as a data source and configure it to combine PreparedStatements.

+1
source

All Articles