@@ -41,8 +41,8 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
41
41
42
42
// We use ThreadLocal for SimpleDateFormat's because they are not that
43
43
// 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
46
46
47
47
/**
48
48
* Constructor for the PreparedStatement class.
@@ -64,6 +64,15 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
64
64
65
65
this .sql = sql ;
66
66
this .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
+
67
76
for (i = 0 ; i < sql .length (); ++i )
68
77
{
69
78
int c = sql .charAt (i );
@@ -89,10 +98,11 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
89
98
/**
90
99
* New in 7.1 - overides Statement.close() to dispose of a few local objects
91
100
*/
92
- public void close () throws SQLException {
101
+ public void close () throws SQLException
102
+ {
93
103
// free the ThreadLocal caches
94
104
tl_df .set (null );
95
-
105
+ tl_tsdf . set ( null );
96
106
super .close ();
97
107
}
98
108
@@ -333,10 +343,6 @@ public void setBytes(int parameterIndex, byte x[]) throws SQLException
333
343
public void setDate (int parameterIndex , java .sql .Date x ) throws SQLException
334
344
{
335
345
SimpleDateFormat df = (SimpleDateFormat ) tl_df .get ();
336
- if (df ==null ) {
337
- df = new SimpleDateFormat ("''yyyy-MM-dd''" );
338
- tl_df .set (df );
339
- }
340
346
341
347
set (parameterIndex , df .format (x ));
342
348
@@ -376,10 +382,6 @@ public void setTime(int parameterIndex, Time x) throws SQLException
376
382
public void setTimestamp (int parameterIndex , Timestamp x ) throws SQLException
377
383
{
378
384
SimpleDateFormat 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
- }
383
385
df .setTimeZone (TimeZone .getTimeZone ("GMT" ));
384
386
385
387
// Use the shared StringBuffer
0 commit comments