override the init() method in the servlet
put ur code in the init() method inside.
Then,whenever create the servlet instance,it would invoke the init method automatically.

解决方案 »

  1.   

    To:dmhorse(dmhorse) 
    我是这样做的,但是一操作数据库就报错.我估计可能是有什么环境没配好.你估计是什么原因?
      

  2.   

    In other tricky way,use crontable setup the daily job,if ur system plantform is linux
      

  3.   

    同意楼上的观点,我们做的类似的程序都是加到cron中执行
      

  4.   

    我在Servlet里用定时器用的好好的啊?操作数据库没问题啊?关键是这两个不搭界啊?你出什么错贴上来啊?看一下是什么Exception就知道了