(1)
long time = System.currentTimeMillis();
ResultSet rs = stmt.executeQuery("select * from Tbl_Mms_User where MobilePhone='13956478952'");
System.out.println("xxxxxx:" + (System.currentTimeMillis() - time));
(2)
long time = System.currentTimeMillis();
List list = dao.find("select user from TblMmsUser user where user.MobilePhone=?", mobilePhone, Hibernate.STRING);
System.out.println("BaseReceiver.xxxxxx:" + (System.currentTimeMillis() - time));
这两段代码前一个直接用JDBC用时0,后一个Hibernate用时36
发问的原因中实际系统中用的是后一个,性能有很大问题,一个简单的查询尽用了0.5秒,表在MobilePhone有索引
数据库是SQLServer2000
long time = System.currentTimeMillis();
ResultSet rs = stmt.executeQuery("select * from Tbl_Mms_User where MobilePhone='13956478952'");
System.out.println("xxxxxx:" + (System.currentTimeMillis() - time));
(2)
long time = System.currentTimeMillis();
List list = dao.find("select user from TblMmsUser user where user.MobilePhone=?", mobilePhone, Hibernate.STRING);
System.out.println("BaseReceiver.xxxxxx:" + (System.currentTimeMillis() - time));
这两段代码前一个直接用JDBC用时0,后一个Hibernate用时36
发问的原因中实际系统中用的是后一个,性能有很大问题,一个简单的查询尽用了0.5秒,表在MobilePhone有索引
数据库是SQLServer2000
本文通过两个示例对比了使用JDBC与Hibernate进行数据库查询的性能差异。第一个示例直接使用JDBC查询耗时几乎为0,而第二个示例使用Hibernate查询耗时较长。文章探讨了这种差异的原因及可能的优化方案。

被折叠的 条评论
为什么被折叠?



