@@ -41,8 +41,8 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
4141
4242// We use ThreadLocal for SimpleDateFormat's because they are not that
4343// thread safe, so each calling thread has its own object.
44- private ThreadLocal tl_df =new ThreadLocal ();// setDate() SimpleDateFormat
45- private ThreadLocal tl_tsdf =new ThreadLocal ();// setTimestamp() SimpleDateFormat
44+ private static ThreadLocal tl_df =new ThreadLocal ();// setDate() SimpleDateFormat
45+ private static ThreadLocal tl_tsdf =new ThreadLocal ();// setTimestamp() SimpleDateFormat
4646
4747/**
4848 * Constructor for the PreparedStatement class.
@@ -64,6 +64,15 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
6464
6565this .sql =sql ;
6666this .connection =connection ;
67+
68+ // might just as well create it here, so we don't take the hit later
69+
70+ SimpleDateFormat df =new SimpleDateFormat ("''yyyy-MM-dd''" );
71+ tl_df .set (df );
72+
73+ df =new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
74+ tl_tsdf .set (df );
75+
6776for (i =0 ;i <sql .length (); ++i )
6877{
6978int c =sql .charAt (i );
@@ -89,10 +98,11 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
8998/**
9099 * New in 7.1 - overides Statement.close() to dispose of a few local objects
91100 */
92- public void close ()throws SQLException {
101+ public void close ()throws SQLException
102+ {
93103// free the ThreadLocal caches
94104tl_df .set (null );
95-
105+ tl_tsdf . set ( null );
96106super .close ();
97107 }
98108
@@ -333,10 +343,6 @@ public void setBytes(int parameterIndex, byte x[]) throws SQLException
333343public void setDate (int parameterIndex ,java .sql .Date x )throws SQLException
334344{
335345SimpleDateFormat df = (SimpleDateFormat )tl_df .get ();
336- if (df ==null ) {
337- df =new SimpleDateFormat ("''yyyy-MM-dd''" );
338- tl_df .set (df );
339- }
340346
341347set (parameterIndex ,df .format (x ));
342348
@@ -376,10 +382,6 @@ public void setTime(int parameterIndex, Time x) throws SQLException
376382public void setTimestamp (int parameterIndex ,Timestamp x )throws SQLException
377383 {
378384SimpleDateFormat df = (SimpleDateFormat )tl_tsdf .get ();
379- if (df ==null ) {
380- df =new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
381- tl_tsdf .set (df );
382- }
383385df .setTimeZone (TimeZone .getTimeZone ("GMT" ));
384386
385387// Use the shared StringBuffer