reetesh123
Programmer
All,
I am having a strange problem. All my queries are running 3 times slower when run using a prepared statement having parameters.
Same query works 3 times faster when i embed those parameters in the query itself while making the prepared statement.
I tested this with a simple JAVA jdbc connection class.
Following is the code for making connection and prepared statement.
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection conn = DriverManager.getConnection(url, uname, psswrd);
PreparedStatement psmt =conn.prepareStatement(query);
psmt.setTimestamp(1,new Timestamp(startTimeCal.getTimeInMillis()));
psmt.setTimestamp(2,new Timestamp(endTimeCal.getTimeInMillis()));
ResultSet rs = psmt.executeQuery();
I don't know if this helps, but i tried running the query in two modes with TRACE_ALL enabled in connection. I couldn't understand much from the trace file but following are the execution completion log traces from the file for the two modes:
With parameter:
jccTime:2010-11-17-09:03:33.091Thread:mainPreparedStatement@1572e449 executeQuery () returned com.ibm.db2.jcc.t4.j@d8d9850
jccSystemMonitor:stop core: 14066.455489999998ms | network: 13989.78416ms | server: 13986.041000000001ms
With Parameter embedded in the query:
jccTime:2010-11-17-09:01:34.313Thread:mainPreparedStatement@29e97f9f executeQuery () returned com.ibm.db2.jcc.t4.j@4c5e176f
jccSystemMonitor:stop core: 3846.488966ms | network: 3762.8420109999997ms | server: 3758.717ms
It is not specific to a particular query, its happening for all. Is there any way i can debug this?
I cannot understand this behaviour. Any insight on this is really appreciated.
I am having a strange problem. All my queries are running 3 times slower when run using a prepared statement having parameters.
Same query works 3 times faster when i embed those parameters in the query itself while making the prepared statement.
I tested this with a simple JAVA jdbc connection class.
Following is the code for making connection and prepared statement.
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection conn = DriverManager.getConnection(url, uname, psswrd);
PreparedStatement psmt =conn.prepareStatement(query);
psmt.setTimestamp(1,new Timestamp(startTimeCal.getTimeInMillis()));
psmt.setTimestamp(2,new Timestamp(endTimeCal.getTimeInMillis()));
ResultSet rs = psmt.executeQuery();
I don't know if this helps, but i tried running the query in two modes with TRACE_ALL enabled in connection. I couldn't understand much from the trace file but following are the execution completion log traces from the file for the two modes:
With parameter:
jccTime:2010-11-17-09:03:33.091Thread:mainPreparedStatement@1572e449 executeQuery () returned com.ibm.db2.jcc.t4.j@d8d9850
jccSystemMonitor:stop core: 14066.455489999998ms | network: 13989.78416ms | server: 13986.041000000001ms
With Parameter embedded in the query:
jccTime:2010-11-17-09:01:34.313Thread:mainPreparedStatement@29e97f9f executeQuery () returned com.ibm.db2.jcc.t4.j@4c5e176f
jccSystemMonitor:stop core: 3846.488966ms | network: 3762.8420109999997ms | server: 3758.717ms
It is not specific to a particular query, its happening for all. Is there any way i can debug this?
I cannot understand this behaviour. Any insight on this is really appreciated.