任务代码如下:
static class MyTask extends java.util.TimerTask {
public void run() {
System.out.println("timer.run()");
DBTools d = new DBTools();
Connection conn = null;
PreparedStatement prst = null;
ResultSet rs = null;
try {
conn = d.getMSConn();
prst = conn.prepareStatement("select optiondate from A1A002Log");
rs = prst.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
ex.printStackTrace();
}finally{
try {
if (rs != null) {
rs.close();
}
if (prst != null) {
prst.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex1) {
ex1.printStackTrace();
}
}
}
}
这段程序只打印出timer.run()便无反应,但在debug中单步执行均能正常访问数据库。是不是因为这个任务时间太长而不能执行呢?请高手指点,谢谢!
static class MyTask extends java.util.TimerTask {
public void run() {
System.out.println("timer.run()");
DBTools d = new DBTools();
Connection conn = null;
PreparedStatement prst = null;
ResultSet rs = null;
try {
conn = d.getMSConn();
prst = conn.prepareStatement("select optiondate from A1A002Log");
rs = prst.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
ex.printStackTrace();
}finally{
try {
if (rs != null) {
rs.close();
}
if (prst != null) {
prst.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex1) {
ex1.printStackTrace();
}
}
}
}
这段程序只打印出timer.run()便无反应,但在debug中单步执行均能正常访问数据库。是不是因为这个任务时间太长而不能执行呢?请高手指点,谢谢!
检查你的查询是否查询出结果了,并且检查你的timer是不是定义的执行一次就结束了。
要看你的调用代码,还要看你的查询是否查询出了结果数据