NutzCN Logo
问答 帮忙看看什么问题,sql在数据库里跑过了,没有问题
发布于 2644天前 作者 qq_bf0b70b9 1536 次浏览 复制 上一个帖子 下一个帖子
标签:

String sql="select daily.region,daily.cust_id,daily.case_id,claim.claim_no,claim.claim_no_3rd,\r\n" +
"claim.vin,claim.plate_no,claim.mf_code,claim.model_code,sub_model_code,\r\n" +
"vin_count,preview_count,calculation_count,transaction_count,billing_date \r\n" +
"from billing_log_daily daily,billing_claim_info claim \r\n" +
"where daily.region=@regionInfo and daily.cust_id=@cust_id \r\n" +
"and daily.case_id=claim.case_id\r\n" +
"and daily.cust_id=claim.cust_id\r\n" +
"and daily.region=claim.region \r\n" +
"and daily.billing_date between @StartDate and @EndDate ";

    Sql sqlsearch=Sqls.create(sql);
    sqlsearch.params().set("regionInfo",regionInfo);
    sqlsearch.params().set("cust_id",cust_id.trim());
    sqlsearch.params().set("StartDate",StartDate);
    sqlsearch.params().set("EndDate",EndDate);

    sqlsearch.setCallback(new SqlCallback() {

       @Override
       public Object invoke(Connection conn, ResultSet result, Sql sql) throws SQLException {

         Map<String, String> map=new HashMap<>();
         map.put("region",result.getString("region"));
         map.put("cust_id",result.getString("cust_id"));
         map.put("case_id",result.getString("case_id"));
         map.put("clain_no",result.getString("clain_no"));
         map.put("claim_no_3rd",result.getString("claim_no_3rd"));
         map.put("vin",result.getString("vin"));
         map.put("plate_no",result.getString("plate_no"));
         map.put("mf_code",result.getString("mf_code"));
         map.put("model_code",result.getString("model_code"));
         map.put("sub_model_code",result.getString("sub_model_code"));
         map.put("vin_count",result.getString("vin_count"));
         map.put("preview_count",result.getString("preview_count"));
         map.put("calculation_count",result.getString("calculation_count"));
         map.put("transaction_count",result.getString("transaction_count"));
         map.put("billing_date",result.getString("billing_date"));

         Iterator<Map.Entry<String,String>> entries = map.entrySet().iterator();  
              while (entries.hasNext()) {  
                 Map.Entry<String,String> entry = entries.next();  
                  System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());  
         }  
         return null;
       }
    });
    dao.execute(sqlsearch);
16 回复

用 插入代码 按钮重新贴一次

String sql="select daily.region,daily.cust_id,daily.case_id,claim.claim_no,claim.claim_no_3rd,\r\n" + 
				"claim.vin,claim.plate_no,claim.mf_code,claim.model_code,sub_model_code,\r\n" + 
				"vin_count,preview_count,calculation_count,transaction_count,billing_date \r\n" + 
				"from billing_log_daily daily,billing_claim_info claim \r\n" + 
				"where daily.region= @regionInfo and daily.cust_id= @cust_id \r\n" + 
				"and daily.case_id=claim.case_id \r\n" + 
				"and daily.cust_id=claim.cust_id \r\n" + 
				"and daily.region=claim.region  \r\n" + 
				"and daily.billing_date between @StartDate and @EndDate " ;
		
		Sql sqlsearch=Sqls.create(sql);
		sqlsearch.params().set("regionInfo",regionInfo);
		sqlsearch.params().set("cust_id",cust_id.trim());
		sqlsearch.params().set("StartDate",StartDate);
		sqlsearch.params().set("EndDate",EndDate);
		
		sqlsearch.setCallback(new SqlCallback() {
			
			@Override
			public Object invoke(Connection conn, ResultSet result, Sql sql) throws SQLException {
				
				Map<String, String> map=new HashMap<>();
				map.put("region",result.getString("region"));
				map.put("cust_id",result.getString("cust_id"));
				map.put("case_id",result.getString("case_id"));
				map.put("clain_no",result.getString("clain_no"));
				map.put("claim_no_3rd",result.getString("claim_no_3rd"));
				map.put("vin",result.getString("vin"));
				map.put("plate_no",result.getString("plate_no"));
				map.put("mf_code",result.getString("mf_code"));
				map.put("model_code",result.getString("model_code"));
				map.put("sub_model_code",result.getString("sub_model_code"));
				map.put("vin_count",result.getString("vin_count"));
				map.put("preview_count",result.getString("preview_count"));
				map.put("calculation_count",result.getString("calculation_count"));
				map.put("transaction_count",result.getString("transaction_count"));
				map.put("billing_date",result.getString("billing_date"));
				
				Iterator<Map.Entry<String,String>> entries = map.entrySet().iterator();  
						while (entries.hasNext()) {  
							Map.Entry<String,String> entry = entries.next();  
						    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());  
				}  
				return null;
			}
		});
		
		dao.execute(sqlsearch);
异常:
!Nutz SQL Error: 'select daily.region,daily.cust_id,daily.case_id,claim.claim_no,claim.claim_no_3rd,
claim.vin,claim.plate_no,claim.mf_code,claim.model_code,sub_model_code,
vin_count,preview_count,calculation_count,transaction_count,billing_date 
from billing_log_daily daily,billing_claim_info claim 
where daily.region= 'CN' and daily.cust_id= '300003' 
and daily.case_id=claim.case_id 
and daily.cust_id=claim.cust_id 
and daily.region=claim.region  
and daily.billing_date between '2017-04-19' and '2017-05-30''
PreparedStatement: 
'select daily.region,daily.cust_id,daily.case_id,claim.claim_no,claim.claim_no_3rd,
claim.vin,claim.plate_no,claim.mf_code,claim.model_code,sub_model_code,
vin_count,preview_count,calculation_count,transaction_count,billing_date 
from billing_log_daily daily,billing_claim_info claim 
where daily.region= ? and daily.cust_id= ? 
and daily.case_id=claim.case_id 
and daily.cust_id=claim.cust_id 
and daily.region=claim.region  
and daily.billing_date between ? and ?'
CaseMessage=null
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:236)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:1008)
	at com.audatex.apac1.billing.module.XyModule.SearchInfo(XyModule.java:231)
	at com.audatex.apac1.billing.module.XyModule$FM$SearchInfo$ad2b5a4f47a0df84dab2528e562aff89.invoke(XyModule.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
	at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:815)
	at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5528)
	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5448)
	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5488)
	at com.alibaba.druid.pool.DruidPooledResultSet.getString(DruidPooledResultSet.java:257)
	at com.audatex.apac1.billing.module.XyModule$2.invoke(XyModule.java:206)
	at org.nutz.dao.impl.sql.NutSql.onAfter(NutSql.java:136)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:277)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	... 48 more

逐渐减少where的条件,看看哪一个条件导致的问题

我发现是你自己写的回调抛出异常

at com.audatex.apac1.billing.module.XyModule$2.invoke(XyModule.java:206)

我在数据库里跑了这条语句,能跑起来为什么还会报异常

语句没有错,是回调的代码错了

报错的是206行

回调函数能返回map类型吗?

Sqls.callback.xxxx 里面选

抱歉刚学这个框架,像上面的情况,我自定义了回调函数,怎么接收返回的map

sql.setCallback(Sqls.callback.map());

sqlsearch.setCallback(new SqlCallback() {
@Override
public Map<String,String> invoke(Connection conn, ResultSet result, Sql sql) throws SQLException {

         Map<String, String> map=new HashMap<>();
         map.put("region",result.getString("region"));
         map.put("cust_id",result.getString("cust_id"));
         map.put("case_id",result.getString("case_id"));
         map.put("clain_no",result.getString("clain_no"));
         map.put("claim_no_3rd",result.getString("claim_no_3rd"));
         map.put("vin",result.getString("vin"));
         map.put("plate_no",result.getString("plate_no"));
         map.put("mf_code",result.getString("mf_code"));
         map.put("model_code",result.getString("model_code"));
         map.put("sub_model_code",result.getString("sub_model_code"));
         map.put("vin_count",result.getString("vin_count"));
         map.put("preview_count",result.getString("preview_count"));
         map.put("calculation_count",result.getString("calculation_count"));
         map.put("transaction_count",result.getString("transaction_count"));
         map.put("billing_date",result.getString("billing_date"));

         return map;
       }
    });
    sqlsearch.setCallback(Sqls.callback.map());
    dao.execute(sqlsearch);
    Map<String,String> map=sqlsearch.getObject(Map.class);

这样对吗??

去掉你自己写的回调

删掉你的 sqlsearch.setCallback(new SqlCallback() {

真心谢谢,能跑了

添加回复
请先登陆
回到顶部