cron.com.abc.biz.controller.quartz.ImportInfoPerFiveMinRun=0 0/5 * * * ?
@IocBean(fields = {"dao" })
@At("/importInfo")
public class ImportInfoPerFiveMinRun implements Job {
private static final Log log =Logs.get();
private Dao dao;
private static Dao daoWang;
private static DruidDataSource dsWang=new DruidDataSource();
static {
try{
dsWang.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
dsWang.setUrl("jdbc:sqlserver://192.168.0.1:1433;databaseName=abc");
dsWang.setUsername("sa");
dsWang.setPassword("sa123456");
daoWang = new NutDao(dsWang);
}catch(Exception ex){
ex.printStackTrace();
}
}
public void start(){
String strSql="select TOP 50 * from table order by id desc";
Sql sql = Sqls.queryEntity(strSql);
sql.setEntity(daoWang.getEntity(Record.class));
daoWang.execute(sql); //在这里抛异常
//org.quartz.JobExecutionException: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.nutz.dao.DaoException: !Nutz SQL Error: 'select TOP 50 * from table order by id desc'
List<Record> infos= sql.getList(null);
for(Record info:infos){
Integer res=insertToInfo(info); //从sqlserver读出来使用dao写入mysql
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
6 回复
这个写法是错误的, Record并非一个Entity, Pojo类才是Entity.
Sql sql = Sqls.queryEntity(strSql);
sql.setEntity(daoWang.getEntity(Record.class));
改成
Sql sql = Sqls.queryRecord(strSql); // 不需要setEntity.
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:249)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:66)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:204)
at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:182)
at com.youfang.biz.controller.quartz.ImportInfoPerFiveMinRun.start(ImportInfoPerFiveMinRun.java:165)
at com.youfang.biz.controller.quartz.ImportInfoPerFiveMinRun.execute(ImportInfoPerFiveMinRun.java:295)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1352)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1339)
at com.microsoft.sqlserver.jdbc.TDSChannel.write(IOBuffer.java:1670)
at com.microsoft.sqlserver.jdbc.TDSWriter.flush(IOBuffer.java:2486)
at com.microsoft.sqlserver.jdbc.TDSWriter.writePacket(IOBuffer.java:2388)
at com.microsoft.sqlserver.jdbc.TDSWriter.endMessage(IOBuffer.java:1995)
at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4992)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:773)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:611)
at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:143)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:195)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:43)
添加回复
请先登陆