我的代码是这样的:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= DriverManager.getConnection(url,user,pw);
Statement stmt=conn.createStatement();
String id=request.getParameter("chapters");
String id2=request.getParameter("theme");
String s="select count(*) as n1 from 单选题 where 章节='"+id+"' and 科目='"+id2+"'";
String bdx="select count(*) as n2 from 不定项 where 章节='"+id+"' and 科目='"+id2+"'";
String pdt="select count(*) as n3 from 判断题 where 章节='"+id+"' and 科目='"+id2+"'";
String mcjs="select count(*) as n4 from 名词解释 where 章节='"+id+"' and 科目='"+id2+"'";
String tkt="select count(*) as n5 from 填空题 where 章节='"+id+"' and 科目='"+id2+"'";
String jdt="select count(*) as n6 from 简答题 where 章节='"+id+"' and 科目='"+id2+"'";
String rst="select count(*) as n7 from 论述题 where 章节='"+id+"' and 科目='"+id2+"'";
ResultSet s1=stmt.executeQuery(s);
s1.next();
int ns1=s1.getInt("n1");
out.print(ns1);
...............................
................................
ResultSet s2=stmt.executeQuery(bdx);
s2.next();
int ns2=s2.getInt("n2");
out.print(ns2);
问题是:
这样编译的话就定死了,java占CPU百分之90多
去掉s2.next();
又提示没有找到定点光标
有没有人知道的说一声音好吗,很急
----------------解决方案--------------------------------------------------------
是持续一会儿还是很久?因为如果连续执行 stmt.executeQuery 这么多次 一会儿的高占用率是正常的。
----------------解决方案--------------------------------------------------------
建议楼主用存储过程做 这样数据的增删改全在数据库服务上完成
不会占用编程工具的内存
----------------解决方案--------------------------------------------------------
1.首先如果你说的是编译导致cpu占用过高,似乎不可能,如果编译就发生过高,那么你机器有问题
2。如果是运行时过高继续下面的解决办法
1。手动执行各条sql语句,在数据库中,察看他们用了多长时间,那么在java中也至少需要这么长时间
2。建议count(*)修改为count(id)这样快很多
3。程序resultset最好取值用while(rs.next()){}虽然count一定会有记录也就是rs.next()一定存在,也要养成良好的习惯
3。建议检查连接是否close了,资源是否及时释放
----------------解决方案--------------------------------------------------------