java循环问题求解?谢谢各位啦!

xinhuagong 2003-06-04 04:30:21
public static void main(String args[]) {
String sql = "select * from [File] where Is_Send=1";
byte[] byteArray=null;
for(;;){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String s = "jdbc:odbc:test";
Connection con = DriverManager.getConnection(s,"sa","88888");
Statement stmt = con.createStatement();
Connection con1 = DriverManager.getConnection(s,"sa","88888");
Statement stmt1 = con1.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while ( rs.next()) {
int ID=rs.getInt("ID");
byteArray=rs.getBytes("File_Bit");
senderID = rs.getString("SendID");
recipientID = rs.getString("ReceiveID");
targetType = rs.getString("MobileType");
smil = readfile(smilName);
gif = byteArray;
doUpload();
strSQL = "update [File] set Is_Send=0 where ID="+ID+"";
System.out.println(strSQL);
stmt1.executeUpdate(strSQL);
System.out.println("OK!!");
}
rs.close();
stmt.close();
stmt1.close();
con1.close();
con.close();
}
catch(Exception e)
{
System.out.println("error!!!!");

}
我这个程序的for循环太占CPU资源了,我想让它没有发现新记录时休息5秒,应该如何做呢?
...全文
26 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinhuagong 2003-06-04
  • 打赏
  • 举报
回复
各位,帮帮忙啦!
trust_me 2003-06-04
  • 打赏
  • 举报
回复
定义一个全局变量static ResultSet rs1 = null;
然后,
while ( rs.next()) {
int ID=rs.getInt("ID");
byteArray=rs.getBytes("File_Bit");
senderID = rs.getString("SendID");
recipientID = rs.getString("ReceiveID");
targetType = rs.getString("MobileType");
smil = readfile(smilName);
gif = byteArray;
doUpload();
strSQL = "update [File] set Is_Send=0 where ID="+ID+"";
System.out.println(strSQL);
stmt1.executeUpdate(strSQL);
System.out.println("OK!!");
}
if(rs.equals(rs1)){
try {
Thread.sleep(5000);
}
catch (InterruptedException ex) {
}
}
rs.close();
不知道行不行,试试吧!
kindlemoney 2003-06-04
  • 打赏
  • 举报
回复
sleep(5000);

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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