mysql查询5000条以上数据,不报错,但也不返回查询结果

bright_mood 2012-10-23 11:48:57
大神求破!
这是数据库连接代码

public static Connection getConn(){
Connection con=null;
try {

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web","root", "ROOT");


}catch (SQLException e) {
e.printStackTrace();
}

return con;
}

查询代码如下

public List<Text> queryAll() {
// TODO Auto-generated method stub
Connection conn = DBConnection.getConn();
String sql = "select id, title, classfi, body, date,commNum from news where classfi = '2' limit 5000;";
List<Text> texts = new ArrayList<Text>();
try {
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()){
Text text = new Text();
text.setTextId(rs.getInt("id"));
text.setTitle(rs.getString("title"));
text.setClassfi(Integer.parseInt(rs.getString("classfi").trim()));
text.setBody(rs.getString("body"));
String date = rs.getString("date");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
text.setTime(sdf.parse(date));
text.setAttention(rs.getInt("commNum"));
//text.setTagging(rs.getString("tagging"));
text.setFrom(-1);
texts.add(text);
}
DBConnection.close(rs, ps, conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return texts;
}

调用此函数时,程序一直陷入此函数中,占用CPU一直为0,占用内存未定不变。但是查询3000条数据时,16秒就得到结果,这是什么原因呢?
...全文
479 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ByLia 2012-10-23
  • 打赏
  • 举报
回复
还在查,卡住了?
开启时代 2012-10-23
  • 打赏
  • 举报
回复
请查下大于5000时是否有问题数据 如果无问题 在mysql里执行下查询看看需要多久出结果。
bright_mood 2012-10-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

请查下大于5000时是否有问题数据 如果无问题 在mysql里执行下查询看看需要多久出结果。
[/Quote]
大于5000也有问题,就是5000左右会出现问题,在navicat下能够查询得到结果,大概16秒
rucypli 2012-10-23
  • 打赏
  • 举报
回复
cpu为0 那io呢

56,681

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧