Here's the code :
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
public class Db2Query {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "select * from ( select rownumber() over() as rownumber_, event0.event_id from t_event event0_ left outer join t_event_type eventtype1_ on event0_.evt_name_hash=eventtype1_.ett_name_hash left outer join t_protocol_to_rule protocolto2_ on eventtype1_.ett_protocol_rule_id=protocolto2_.ptr_id left outer join t_application applicatio3_ on protocolto2_.ptr_app_id=applicatio3_.app_id where event0_.evt_parent_id=? " +
"and event0_.evt_start_time between ? and ? order by event0_.evt_start_time DESC FETCH FIRST 26 ROWS ONLY ) as temp_ where rownumber_ <= ?";
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
conn = DriverManager.getConnection("jdbc:db2://localhost:50040/spdb2", "db2sp", "correl");
long t = System.currentTimeMillis();
System.out.println("1");
stmt = conn.prepareStatement(sql);
System.out.println("2");
stmt.setLong(1, 0);
Timestamp t1 = new Timestamp(110,0,7,0,0,0,0);
System.out.println("3");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");
String timestamp = simpleDateFormat.format(t1);
System.out.println(timestamp);
System.out.println("4");
stmt.setTimestamp(2, t1);
System.out.println("5");
Timestamp t2 = new Timestamp(110,0,7,23,59,59,0);
//String timestamp2 = simpleDateFormat.format(t2);
stmt.setTimestamp(3, t2);
System.out.println("6");
stmt.setLong(4, 26);
System.out.println("7");
rs = stmt.executeQuery();
System.out.println("8");
System.out.println(" " + (System.currentTimeMillis()-t) + "ms");
while (rs.next()) {
System.out.println(rs.getString(2));
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {stmt.close();}catch (Exception e){}
try {conn.close();}catch (Exception e){}
}
}
}
I'm not getting errors , just low performance.
By running the same query with the timestamp fields inline , it will be executed fast.
10x.