mysql查询在数据库正常,但是在java里就报错

select i.id,i.price,i.amount,g.name from orderitem i ,goods g where order_id = ? and i.goods_id = g.id
java.sql.SQLException: Cannot create com.yanzi.model.OrderItem: com.yanzi.model.OrderItem Query: select i.id,i.price,i.amount,g.name from orderitem i ,goods g where order_id = ? and i.goods_id = g.id Parameters: [9]


public List<OrderItem> selectAllItem(int orderid) throws SQLException {
    QueryRunner r = new QueryRunner(DBUtil.getDataSource());        
    String sql = "select i.id,i.price,i.amount,g.name from orderitem i ,goods g where order_id = ? and i.goods_id = g.id";
    System.out.println(sql);
    return r.query(sql, new BeanListHandler<OrderItem>(OrderItem.class),orderid);
}
0

3个回答

先这样写

public List<Map< String, Object>> selectAllItem(int orderid) throws SQLException {
QueryRunner r = new QueryRunner(DBUtil.getDataSource());

String sql = "select i.id,i.price,i.amount,g.name from orderitem i ,goods g where order_id = ? and i.goods_id = g.id";
System.out.println(sql);
return r.query(sql, new MapListHandler(),orderid);
}
看报不报错,没错的话sql没问题;
接下来检查 OrderItem 有没public 无参构造方法,字段名与SQL 列的对应关系。

参考demo: https://gitee.com/00fly/java-code-frame/tree/master/dbutils-jdbc

0
qq_35669619
燕子18 谢谢,就是OrderItem没有设置无参构造方法。
8 个月之前 回复

select i.id,i.price,i.amount,g.name from orderitem i ,goods g where order_id = ? and i.goods_id = g.id
java.sql.SQLException: Cannot create com.yanzi.model.OrderItem: com.yanzi.model.OrderItem Query: select i.id,i.price,i.amount,g.name from orderitem i ,goods g where order_id = ? and i.goods_id = g.id Parameters: [9]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:527)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:391)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:329)
at com.yanzi.dao.OrderDao.selectAllItem(OrderDao.java:50)
at com.yanzi.service.OrderService.selectAll(OrderService.java:53)
at com.yanzi.servelt.OrderListServlet.doGet(OrderListServlet.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.yanzi.filter.EncodeFilter.doFilter(EncodeFilter.java:40)
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:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
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:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
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)

0

你先把id去了查询 如果报错那么恭喜你是配置错误,如果没出错,恭喜你id值没赋值上

0
qq_35669619
燕子18 解决了,是因为OrderItem类里没有设置无参构造方法
8 个月之前 回复
qq_35669619
燕子18 id设置成固定值也是报错:Wrong number of parameters: expected 0, was given 1 Query: select i.id,i.price,i.amount,g.name from orderitem i,goods g where order_id = 2 and i.goods_id = g.id Parameters: [2]
8 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
SQL语句在数据库可以正常查询,但是在程序引用时却总是报错
rninsert into RB_ZLRB(date,zt_bll,zt_mbz,xz_bll,xz_mbz,hck_bll,hck_mbz,dg_bll,dg_mbz,jd_bll,jd_mbz,mk_bll,mk_mbz,bm_bll,bm_mbz,dc_bll,dc_mbz,mt_bll,mt_mbz,fj_bll,fj_mbz,a_bll,a_mbz,b_bll,b_mbz,mkl_bll,mkl_mbz,bml_bll,bml_mbz,dcl_bll,dcl_mbz,mtl_bll,mtl_mbz,fjl_bll,fjl_mbz,qcl_bll,qcl_mbz,tpv_bll,tpv_mbz,gj_bll,gj_mbz,ycl_bll,ycl_mbz,wg_bll,wg_mbz,gc_bll,gc_mbz,jz_scsl,jz_blsl,jz_bll,jz_mbz,mft_scsl,mft_blsl,mft_bll,mft_mbz,jzzj_jypc,jzzj_blpc,jzzj_bll,jzzj_mbz, jh_jypc, jh_blpc, jh_bll, jh_mbz, tpv_jypc, tpv_blpc, tpv_bll,rntpv_mbz,bf_qcl,bf_lh,bf_jc,bf_jh,zxs_wtgj,dq_wtgj,aq_wtgj,zxs_wtyf,dq_wtyf,aq_wtyf,zxs_jytl,dq_jytl,aq_jytl,zxs_glxt,dq_glxt,aq_glxt) select LH_ZT.date,SUM(LH_ZT.lh_fq)/SUM(LH_ZT.lh_cl)*1000000 as zt_bll,MBZ_LH.zt_mbz, SUM(LH_XZ.lh_fq)/SUM(LH_XZ.lh_cl)*1000000 as xz_bll,MBZ_LH.xz_mbz as xz_mbz,SUM(LH_HCK.lh_fq)/SUM(LH_HCK.lh_cl)*1000000 as hck_bll,MBZ_LH.hck_mbz as hck_mbz,SUM(LH_DG.lh_fq)/SUM(LH_DG.lh_cl)*1000000 as dg_bll,MBZ_LH.dg_mbz as dg_mbz,SUM(LH_JD.lh_fq)/SUM(LH_JD.lh_cl)*1000000 as jd_bll ,MBZ_LH.jd_mbz as jd_mbz,(sum (JH_RBB.jh_fgzl)+sum(JH_RBB.jh_bfzl))/sum(JH_RBB.jh_jhzl)*1000000 AS mk_bll ,MBZ_JH.mk_mbz as mk_mbz,(sum (d.jh_fgzl)+sum(d.jh_bfzl))/sum(d.jh_jhzl)*1000000 AS bm_bll ,MBZ_JH.bm_mbz as bm_mbz,(sum (e.jh_fgzl)+sum(e.jh_bfzl))/sum(e.jh_jhzl)*1000000 AS dc_bll, MBZ_JH.dc_mbz as dc_mbz,(sum (f.jh_fgzl)+sum(f.jh_bfzl))/sum(f.jh_jhzl)*1000000 AS mt_bll,MBZ_JH.mt_mbz as mt_mbz ,(sum (g.jh_fgzl)+sum(g.jh_bfzl))/sum(g.jh_jhzl)*1000000 AS fj_bll,MBZ_JH.fj_mbz AS fj_mbz, SUM(LJ_ZLRB.lj_blcs)/ sum(LJ_ZLRB.lj_sccs)*1000000 as a_bll,MBZ_LJ.a_mbz AS a_mbz,SUM(a1.lj_blcs)/ sum(a1.lj_sccs)*1000000 as b_bll,MBZ_LJ.b_mbz AS b_mbz ,(sum (JC_JCGC.jc_ssje)+sum(JC_FLTH.jc_je)+sum(JC_BJ.jc_bfje)+sum(JC_CLBLP.jc_bfje))/sum(JC_JCJH.jc_decz)*1000000 AS mkl_bll ,MBZ_JC.mkl_mbz as mkl_mbz, (sum (h.jc_ssje)+sum(i.jc_je)+sum(j.jc_bfje)+sum(k.jc_bfje))/sum(l.jc_decz)*1000000 AS bml_bll ,MBZ_JC.bml_mbz as bml_mbz, (sum (m.jc_ssje)+sum(n.jc_je)+sum(o.jc_bfje)+sum(p.jc_bfje))/sum(q.jc_decz)*1000000 AS dcl_bll, MBZ_JC.dcl_mbz as dcl_mbz, (sum (r.jc_ssje)+sum(x.jc_je)+sum(t.jc_bfje)+sum(u.jc_bfje))/sum(v.jc_decz)*1000000 AS mtl_bll,MBZ_JC.mtl_mbz as mtl_mbz , (sum (w.jc_ssje)+sum(s.jc_je)+sum(y.jc_bfje)+sum(z.jc_bfje))/sum(aa.jc_decz)*1000000 AS fjl_bll, MBZ_JC.fjl_mbz as fjl_mbz, SUM(qcl_wtbkt)/SUM(qcl_cl)*1000000 AS qcl_bll, MBZ_QCL.qcl_mbz AS qcl_mbz, SUM(TPV_SCGC_JH.tpv_blsl)/ sum(TPV_SCGC_JH.tpv_jhsl)*1000000 as tpv_bll,MBZ_TPV.tpv_mbz AS tpv_mbz, hgl_gj as gj_hgl, mbz_gj as gj_mbz, bll_ycl as ycl_bll, mbz_ycl as ycl_mbz, bll_wg as wg_bll, mbz_wg as wg_mbz, bll_gc as gc_bll, mbz_gc as gc_mbz,RB_JZ.scsl as jz_scsl,RB_JZ. blsl as jz_blsl,RB_JZ.bll as jz_bll,RB_JZ. mbz as jz_mbz, RB_MFT.scsl as mft_scsl , RB_MFT.blsl as mft_blsl, RB_MFT.bll as mft_bll, RB_MFT.mbz as mft_mbz,jz_jypc as jzzj_jypc,jz_blpc as jzzj_blpc,jz_jzbll as jzzj_jzbll,jz_mbz as jzzj_mbz, jh_jypc as jh_jypc,jh_blpc as jh_blpc,jh_bll as jh_bll,jh_mbz as jh_mbz,tpv_jypc as tpv_jypc,tpv_blpc as tpv_blpc,tpv_bll as tpv_bll, RB_JZZJ.tpv_mbz as tpv_mbz ,je_qcl as bf_qcl,je_lh as bf_lh,je_jc as bf_jc,je_jh as bf_jh ,zxs_wtgj as zxs_wtgj,dq_wtgj as dq_wtgj,aq_wtgj as aq_wtgj,zxs_wtyf as zxs_wtyf,dq_wtyf as dq_wtyf,aq_wtyf as aq_wtyf,zxs_jytl as zxs_jytl,dq_jytl as dq_jytl,aq_jytl as aq_jytl,zxs_glxt as zxs_glxt,dq_glxt as dq_glxt,aq_glxt as aq_glxt FROM LH_ZT join LH_XZ on LH_ZT.date=LH_XZ.date left join MBZ_LH ON MBZ_LH.id=MBZ_LH.id join LH_HCK on LH_XZ.date=LH_HCK.date left join MBZ_LH as a ON MBZ_LH.id=MBZ_LH.id JOIN LH_DG on LH_HCK.date=LH_DG.date left join MBZ_LH as b ON MBZ_LH.id=MBZ_LH.id JOIN LH_JD on LH_DG.id=LH_JD.id left join MBZ_LH as c ON MBZ_LH.id=MBZ_LH.id join JH_RBB ON JH_RBB.date=LH_ZT.date inner join MBZ_JH on MBZ_JH.id=MBZ_JH.id join JH_RBB as d on d.date=LH_ZT.date JOIN JH_RBB as e on e.date=LH_ZT.date join JH_RBB as f on f.date=LH_ZT.date join JH_RBB as g on g.date=LH_ZT.date inner join MBZ_LJ ON MBZ_LJ.id=MBZ_LJ.id,JC_JCGC AS h join JC_FLTH as i on i.date=h.date join JC_BJ as j on j.date=i.date join JC_CLBLP as k on k.date=j.date join JC_JCJH as l on l.date=k.date join JC_JCGC AS m on m.date=l.date join JC_FLTH as n on n.date=m.date join JC_BJ as o on o.date=n.date join JC_CLBLP as p on p.date=o.date join JC_JCJH as q on q.date=p.date join JC_JCGC AS r on r.date=q.date join JC_FLTH as x on x.date=r.date join JC_BJ as t on t.date=x.date join JC_CLBLP as u on u.date=x.date join JC_JCJH as v on v.date=u.date join JC_JCGC on JC_JCGC. date=u.date join JC_FLTH on JC_FLTH. date=u.date join JC_BJ on JC_BJ. date=u.date join JC_CLBLP on JC_CLBLP.date=u.date join JC_JCJH on JC_JCJH.date=u.date join JC_JCGC AS w on w.date=v.date join JC_FLTH as s on s.date=w.date join JC_BJ as y on y.date=s.date join JC_CLBLP as z on z.date=y.date join JC_JCJH as aa on aa.date=z.date join MBZ_JC on MBZ_JC.id=MBZ_JC.id JOIN QCL_HZ on QCL_HZ.date=h.date join MBZ_QCL on MBZ_QCL.id=MBZ_QCL.id join TPV_SCGC_JH on TPV_SCGC_JH.date=h.date join MBZ_TPV on MBZ_TPV.id=MBZ_TPV.id rnjoin LJ_ZLRB on LJ_ZLRB.date=h.date JOIN LJ_ZLRB AS a1 on a1.date=LJ_ZLRB.date join RB on RB.date=h.date join RB_JZ on RB_JZ.date=h.date join RB_MFT on RB_MFT.date=h.date join RB_JZZJ on RB_JZZJ.date=h.date join RB_BFSS on RB_BFSS.date=h.date join RB_BRTS on RB_BRTS.date=h.date where LH_ZT.date=convert(varchar(10),getdate()- 1,120) AND LH_XZ.date=convert(varchar(10),getdate()- 1,120) AND LH_HCK.date=convert(varchar(10),getdate()- 1,120) AND LH_DG.date=convert(varchar(10),getdate()- 1,120) AND LH_HCK.date=convert(varchar(10),getdate()- 1,120) AND LH_JD.date=convert(varchar(10),getdate()- 1,120) AND JH_RBB.date=convert(varchar(10),getdate()- 1,120) and JH_RBB.jh_lb='门框类' and d.date=convert(varchar(10),getdate()- 1,120) and d.jh_lb='背门类' and e.date=convert(varchar(10),getdate()- 1,120) and e.jh_lb='导槽类' and f.date=convert(varchar(10),getdate()- 1,120) and f.jh_lb='门条类' and g.date=convert(varchar(10),getdate()- 1,120) and g.jh_lb='附件类' and JC_JCGC.date=convert(varchar(10),getdate()- 1,120) and JC_JCGC.jc_lb='门框' and JC_FLTH.date=convert(varchar(10),getdate()- 1,120) and JC_FLTH.jc_lb='门框' and JC_BJ.date=convert(varchar(10),getdate()- 1,120) and JC_BJ.jc_lb='门框' AND JC_CLBLP.date=convert(varchar(10),getdate()- 1,120) and JC_CLBLP.jc_lb='门框' AND JC_JCJH.date=convert(varchar(10),getdate()- 1,120) and JC_JCJH.jc_lb='门框' AND h.date=convert(varchar(10),getdate()- 1,120) and h.jc_lb='背门' AND i.date=convert(varchar(10),getdate()- 1,120) and i.jc_lb='背门' AND j.date=convert(varchar(10),getdate()- 1,120) and j.jc_lb='背门' AND k.date=convert(varchar(10),getdate()- 1,120) and k.jc_lb='背门' AND l.date=convert(varchar(10),getdate()- 1,120) and l.jc_lb='背门' AND m.date=convert(varchar(10),getdate()- 1,120) and m.jc_lb='导槽' AND n.date=convert(varchar(10),getdate()- 1,120) and n.jc_lb='导槽' AND o.date=convert(varchar(10),getdate()- 1,120) and o.jc_lb='导槽' AND p.date=convert(varchar(10),getdate()- 1,120) and p.jc_lb='导槽' AND q.date=convert(varchar(10),getdate()- 1,120) and q.jc_lb='导槽' AND r.date=convert(varchar(10),getdate()- 1,120) and r.jc_lb='门条' AND x.date=convert(varchar(10),getdate()- 1,120) and x.jc_lb='门条' AND t.date=convert(varchar(10),getdate()- 1,120) and t.jc_lb='门条' AND u.date=convert(varchar(10),getdate()- 1,120) and u.jc_lb='门条' AND v.date=convert(varchar(10),getdate()- 1,120) and v.jc_lb='门条' AND w.date=convert(varchar(10),getdate()- 1,120) and w.jc_lb='附件' AND s.date=convert(varchar(10),getdate()- 1,120) and s.jc_lb='附件' AND y.date=convert(varchar(10),getdate()- 1,120) and y.jc_lb='附件' AND z.date=convert(varchar(10),getdate()- 1,120) and z.jc_lb='附件' AND aa.date=convert(varchar(10),getdate()- 1,120) and aa.jc_lb='附件' AND QCL_HZ.date=convert(varchar(10),getdate()- 1,120) and TPV_SCGC_JH.date=convert(varchar(10),getdate()- 1,120) and LJ_ZLRB.date=convert(varchar(10),getdate()- 1,120) AND LJ_ZLRB.lj_lx='A段胶' and a1.date=convert(varchar(10),getdate()- 1,120) and a1.lj_lx='B段胶' and RB.date=convert(varchar(10),getdate()- 1,120) AND RB_JZ.date=convert(varchar(10),getdate()- 1,120) AND RB_MFT.date=convert(varchar(10),getdate()- 1,120) AND RB_JZZJ.date=convert(varchar(10),getdate()- 1,120) AND RB_BFSS.date=convert(varchar(10),getdate()- 1,120) AND RB_BRTS.date=convert(varchar(10),getdate()- 1,120) group by LH_ZT.date ,MBZ_LH.zt_mbz, MBZ_LH.xz_mbz, MBZ_LH.hck_mbz, MBZ_LH.dg_mbz, MBZ_LH.jd_mbz,JH_RBB.jh_fgzl,JH_RBB.jh_bfzl,JH_RBB.jh_jhzl,MBZ_JH.mk_mbz,MBZ_JH.bm_mbz,MBZ_JH.dc_mbz,MBZ_JH.mt_mbz,MBZ_JH.fj_mbz,MBZ_LJ.a_mbz,MBZ_LJ.b_mbz,MBZ_JC.mkl_mbz,MBZ_JC.bml_mbz,MBZ_JC.dcl_mbz,MBZ_JC.mtl_mbz,MBZ_JC.fjl_mbz , MBZ_QCL.qcl_mbz, MBZ_TPV.tpv_mbz, MBZ_LJ.a_mbz,MBZ_LJ.b_mbz,RB.hgl_gj,RB.mbz_gj,RB.bll_ycl,RB.mbz_ycl,RB.bll_wg,RB.mbz_wg,RB.bll_gc,RB.mbz_gc,RB_JZ.scsl,RB_JZ.blsl,RB_JZ.bll,RB_JZ.mbz, RB_MFT.scsl,RB_MFT.blsl,RB_MFT.bll,RB_MFT.mbz,RB_JZZJ.jz_jypc,RB_JZZJ.jz_blpc,RB_JZZJ.jz_jzbll,RB_JZZJ.jz_mbz,RB_JZZJ.jh_jypc,RB_JZZJ.jh_blpc,RB_JZZJ.jh_bll,RB_JZZJ.jh_mbz,RB_JZZJ.tpv_jypc,RB_JZZJ.tpv_blpc,RB_JZZJ.tpv_bll,RB_JZZJ.tpv_mbz,RB_BFSS. je_qcl, RB_BFSS.je_lh, RB_BFSS.je_jc, RB_BFSS.je_jh, RB_BRTS. zxs_wtgj, RB_BRTS. dq_wtgj, RB_BRTS. aq_wtgj, RB_BRTS. zxs_wtyf, RB_BRTS. dq_wtyf, RB_BRTS. aq_wtyf, RB_BRTS. zxs_jytl, RB_BRTS. dq_jytl, RB_BRTS. aq_jytl, RB_BRTS. zxs_glxt, RB_BRTS. dq_glxt, RB_BRTS. aq_glxtrnrnrn在VS中引用时总是有红线标红,无法引用,如何解决?
在数据库插入中文报错
类似这样的错误,属于编码问题。解决方法:将字段的属性更改为utf8-unicode-ci。
mysql在数据库命令行操作基础应用
--查看当前在什么数据库里面select database();-- 数据库的备份与恢复-- 备份mysqldump -uroot -p 备份的数据库名称 &amp;gt; xx.sql            // (表示定向输出到xx.sql)-- 恢复1.新建一个数据库  python_restore2. mysql -uroot -p python_restore &amp;lt; xx.sql     -...
Java中在数据库查询数据
有这样一张表(编号(id) 地区(place) 厂家(work) 交易记录(deal) 交易人数(num) 交易资金(money)).rnrn我想要在jsp页面加载的时候显示 用jstl显示这样的数据rn 地区(place) - 交易笔数(deal) - 参与交易人数(num) - 资金(money)rnrn例如 武汉 3(表示数据有3次交易) 20(3次交易的总人数) 40000(3次交易的总资金)rnrn这样一定会有一次全查询,还有一次把地区作为参数的查询。rn但是在JSP页面中一行要用到这两种查询 还要用循环的在显示rnrn在DAO中怎么写,控制层怎么写,然后在页面中怎么显示rnrn不能写存储过程!!!!
在数据库打开每一个表的时候报错!
如下:“在执行该操作期间发生意外错误,[ms design tools]存储器不足,无法完成操作"rn内存占用正常,CPU占用正常,查毒,没有..
如何在数据库中查询unicode字符串?
在delphi中,使用ADOQuery控件进行查询时怎样才能传递双字节,rn比如说sql语句是:rnvarrn str:widestring;rnwith ADOQuery dornbeginrn clear;rn sql.clear;rn sql.add('select * from B_TABLEK where name=:name');rn parameters[0].value:=str;rn parpered;rn open;rnend;rn我用sql server查询双字节比如韩文时都能够查询,rn但是采用控件的时候却总是查不出来.rn rn请那位大侠能够帮忙,不胜感激.
关于C语言在数据库中的查询
有这样一个查询:rnselect count(*) from tname where col1 like '%XXX%'rn其中,tname是表名,col1是一个字符型字段名。请问各位大虾,在c语言中,这一句怎么写出来,主要是'%XXX%'处。我用一个字符串,a = "'%%XXX%%'"然后用 select count(*) from tname where col1 like :arn但这样也不行。 谁能帮助我,在下将感激不尽。谢谢
时间在数据库中的查询问题
我要将一些日期插到数据库,我作这样的处理:rnrnjava.util.Date date = new java.util.Date(System.currentTimeMillis());rnjava.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");rnString Datetime = df.format(date);rnString sql="insert into table (datetime) values (Datetime)";rn.....rnrn但当要查询数据库的时候,例如要找回10天前的记录,我这样处理:rnint days=10;rnjava.util.Date date = new java.util.Date(System.currentTimeMillis()-days*24*60*60*1000);rnjava.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");rnString BeforeDatetime = df.format(date);rnString sql="select * from table where datetime<=BeforeDatetime";rn....rn这个查询是成功的,rn但如果要查30天以上,BeforeDatetime就不准确了,甚至返回比现在时间还有以后的时间。rnrn我想问下,你们是怎样处理时间在数据库中的查询?
在数据库的查询中使用like的问题
在查询条件中要按照月份进行查询的时候,条件语句为rn a.b_date LIKE '2002-6%' (* 其中a为数据库名称,b_date为datetime类型,长度为8位 *),查询无结果。但如果将a.b_date LIKE '2002-6%'更改为a.b_date>='2002-06-01' and a.b_date<='2002-06-30' 则有结果,谁能解释a.b_date LIKE '2002-6%' 这种写法的错误在哪里???rnrn在线等待!!急
如何在数据库中查询并返回结果
我想在username文本框中输入用户名,然后上数据库USER表中查询是否已存在该用户名,若存在则提示。rn我用的是ASP.NET(C#),MSSQL。rn请各位帮帮忙!rn谢谢啦!
实现查询某人是否在数据库中?
用SQL语句和rs(New ADODB.Recordset)实现查询某人是否在数据库中?
在数据库中用select查询的问题?
数据库字段是2002-6-12rn我想要查询2002-6的所有数据rn我用left的方法,结果有问题rnset rs=server.createobject("adodb.recordset")rnsql="select * from cost where"&left(&"aa,6"&)&"="&aarnrs.open sql,conn,1,2rn请问这个如何解决?
如何取得掩码在数据库中查询?
我在编写查询时,对时间进行查询用‘MASTEREDIT’掩码的取得的时间却不能在数据库中找到相应的数据,数据库的时间字段为日期型,但将时间字段改为文本类型时却可以,为什么?如何解决?rnrn
data在数据库中查询记录?
用data控件连接数据库当前目录下的数据库xsda.mdb,数据库中有一个表 名为 xsxx 有字段 xh , xm , xb , nl , bj ,cj 怎么查询成绩(cj)为 80 。查询结果只要把这些学生的姓名显示在文本筐或标签中,清高手帮忙。
在数据库自动生成的表上查询
数据库由于数据庞大,每个月都会自动生成一张表,例如:ProductInfo表 过一个月就再多处一张ProductInfo1表,我现在要在这些表里面查询数据,应该怎么写查询语句啊?
在数据库中查询时的一个问题?
string zjid = "select * from [zj_info] where major='"+tid+"' or minor.indexof('"+tid+"') and review='0' ";rnrnrn我的意思就是呢,如果minor里面也包含tid字段的话,也显示那一行信息,我的这个不对,想知道有没有类似的方式。
如何在数据库中查询字段的值
请哪位大哥教教我,现在公司急用!!!!!已知某数据库的字段来源,查询该字段的值!
在数据库中如何做or的查询呢?
在数据库中如何做or的查询呢? rnWITH ADOQUERY1 DOrn BEGINrn CLOSE;rn SQL.Clear ; rn SQL.Add('SELECT * FROM SPXX WHERE SP_ID=:A1 OR SPZBM=:A2 OR BARCODE=:A3');rn Parameters.ParamByName('A1').VALUE:=STRTOINT((TRIM(EDIT1.Text)));rn Parameters.ParamByName('A2').VALUE:=((TRIM(EDIT1.Text)));rn Parameters.ParamByName('A3').VALUE:=((TRIM(EDIT1.Text)));rnrn rn OPEN;rn END;rn提示至少一个参数,没有传递数值!!!!
如何在数据库中查询最新更新的表?
在SQL SERVICE 2005中查询rnrn如何在数据库中查询最新更新的表?
delphi在数据库中按尾数查询?
比如在ACCESS数据库中有这么一个编号字段及数据:rnrn编号:rn10003rn10006rn16016rn10626rn16136rn10258rnrn如何查询尾数为6的数据?
关于在数据库中查询的问题
ResultSet rs = null;rn String sql = "select * from managert where managerid=?";rn stmt = new DataBaseA("Gel");rn stmt.prepare(sql);rn stmt.setParater(1, userName);rn rs = stmt.prepareQuery();rn这是一个javabean的部分内容,我想问第2句的数据库查询语句为什么有where managerid=?,这个?代表什么意思啊
如何在数据库中查询一个字段?!!
我是这样做的:rn数据库中有InceptName的字段中有一行是【系统自动】的数据,我这样查的话就报错!rnrnInceptName="系统自动"rnset rs44566 = Server.CreateObject("adodb.recordset")rnsql0021 = "select * from TabGuestBook where InceptName='“& InceptName&"' order by SendTime desc"rnrs44566.open sql0021,conn,1,1rnrn应该怎么样查?
mysql 如何在数据库端行转列
1.把所有订单号为200909032044561840的tracking_no按|为分隔符拼到一个字段中 select order_no,group_concat(tracking_no SEPARATOR '|') from waybill where order_no='200909032044561840 ' group by order_no ...
MySQL在数据库市场获得25%的市场份额
(2007年3月, 加州圣克鲁斯)第三方市场调查机构Evans数据公司最近公布的一系列客户调查数据显示,在过去两年里,MySQL在所有开发者使用的数据库中获得了25%的市场份额。Evans数据公司是专业的软件市场调查机构,它定期提供最新的面向全球开发者的深度调查和IT产业市场情报。Evans公司的本次调查显示,数据库的使用者中有40%是开发人员,而两年前这一数据是32%。Evans数据公司指出...
mysql在数据库级别进行优化
在数据库级别进行优化 使数据库应用程序快速运行的最重要因素是其基本设计: http://www.yayihouse.com/yayishuwu/chapter/1347
SQL文在数据库中运行正常,但是在VS2008中报“缺少右括号”,请问怎么解决!
SELECTrn EQUIPTYPE,rn SUM(CASE WHEN TO_CHAR(APPLDATE,'MM')=12 THEN APPLQTY ELSE '0' END) AS MONTHrn FROMrn I_EQUIPMENT_BUDGETrn WHERErn TO_CHAR(APPLDATE,'YYYY')=TO_CHAR(SYSDATE,'YYYY')rn GROUP BYrn EQUIPTYPErn可以正常运行,但是在 rnWith strSQLrn .Append(" SELECT").Append(vbCrLf)rn .Append(" EQUIPTYPE,").Append(vbCrLf)rn [b] .Append(" SUM(CASE WHEN TO_CHAR(APPLDATE,'MM')=1 THEN APPLQTY ELSE '0' END) MONTH").Append(vbCrLf)[/b]rn .Append(" FROM").Append(vbCrLf)rn .Append(" I_EQUIPMENT_BUDGET").Append(vbCrLf)rn .Append(" WHERE").Append(vbCrLf)rn .Append(" TO_CHAR(APPLDATE,'YYYY')=TO_CHAR(SYSDATE,'YYYY')").Append(vbCrLf)rn .Append(" GROUP BY").Append(vbCrLf)rn .Append(" EQUIPTYPE").Append(vbCrLf)rnEnd With 中说缺少右括号,我个人认为问题出现在黑体部分,但不知如何解决,麻烦个人帮忙!!!
mysql查询的时候报错
Error Code: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'jx_report.user_active_statistics.id' which is not functionally dependent on columns in GRO
项目在myeclipse运行没有报错,但是在tomact运行就报错
[img=https://img-bbs.csdn.net/upload/201406/10/1402389218_294095.jpg][/img]rn上图为myeclipse的运行的信息。rn[img=https://img-bbs.csdn.net/upload/201406/10/1402389450_499870.jpg][/img]rn上图为tomact加载时候的信息。rnrn大概可能加载spring配置文件的时候报错:rn而我的web.xml的spring配置rn rn contextConfigLocationrn classpath:applicationContext-*.xml rn rnrn有2个spring的xml文件,applicationContext-bean.xml和applicationContext-public.xml
怎样在数据库插入图片
怎样在数据库插入图片
字符串数组保存在数据库
java中如何将字符串数组保存在数据库里,求详细一点的,rn最好有代码有步骤……
在数据库中插入图片
我想问一下怎样在数据库中插入图片rn是连接图片的路径还是把图片直接插进去啊!
在数据库的方面
小弟现在对vc有一个小的了解,下面我想应该给自己定一个方向了,我想学数据库的编程,请大哥给我指导,我该怎样学,怎样入门
在数据库中‘+’的用法
我建两个存储过程,但不知道结果是不是一样的,发上来给大家看看给点意见我rncreate proc spClientInfrn@ClientName varchar(8)='%',rnrnasrnselect * from dbo.tClientrnwhere cname like '@clientname%'rngorn另一个是:rncreate proc spClientInfrn@ClientName varchar(8)='%',rn@rnasrnselect * from dbo.tClientrnwhere cname like '@clientname'+'%'rngornrn执行的结果是否一样,这个+的作用是否连接字符串的意思rn
在数据库中保存数据
在数据库中保存数据
在数据库中获取当前时间
oracle: select sysdate from dual; sqlserver: select getdate(); mysql: select sysdate();
在数据库建表的问题
在数据库cmd界面 随便建一个表 和sequence序列有关吗?
图片保存在数据库
图片压缩后保存在数据库,数据库表字段存储图片,小图片存储在数据库
JAVA和数据库的问题!在JAVA里的查讯语句在数据库查询分析器里能用到了JAVA程序里就不一样了那
这是我JAVA代码里的SQL语句:String sqlS="select * from Grinsert where GrNumber like '%"+GrNumber+"%'";rntry rn rn ps = con.prepareStatement(sqlS);rn rs = ps.executeQuery();rn while(rs.next())rn bean.setGrName(rs.getString("GrName"));rn bean.setGrMgr(rs.getString("GrMgr"));rn bean.setGrGenre(rs.getString("GrGenre"));rn bean.setGrKing(rs.getString("GrKing"));rn bean.setGrAddress(rs.getString("GrAddress"));rn bean.setGrPost(rs.getString("GrPost"));rn bean.setGrPhont(rs.getString("GrPhont"));rnrn list.add(bean);rn rn rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn return list;rn此方法返回类型是ArrayList类型rn下面是Action里的代码!rn DBconnectionTest test = new DBconnectionTest();rn try rn rn int GrNumber= loginForm.getGrNumber();rn if(GrNumber>=0)rn ArrayList list= test.select(GrNumber);rn if(list.size()>0)rn request.setAttribute("list", list);rn return mapping.findForward("selects");rn elsern return mapping.findForward("error");rn rn elsern return mapping.findForward("error");rn rn catch (RuntimeException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn return mapping.findForward("error");rn finallyrn test.CloseDB();rn rn这个是在JSP页面里的到数据并显示出来的代码!!rn<%rn ArrayList list = new ArrayList();rn // Iterator it = list.iterator();rn if (request.getAttribute("list") != null) rn list = (ArrayList) request.getAttribute("list");rn //Iterator it = list.iterator();rnrn else rn System.out.println("bean is null");rn rn%>rnrn现在如果输入“00”应该查出三条不同的记录。GrNumber是数据库的主键分别是1001,1002,1003;rn可是程序里如果输入准确的GrNumber查询结果正确,如果输入其他不正确(模糊查询)的,就总输出三条相同的记录;rn大哥大姐门帮忙看看吧,小第初来乍道,多给点鼓励吧 !!停急的这题!rnrn
Java新增修改保存在数据库乱码问题
修改tomcat配置文件 useBodyEncodingForURI="true" URIEncoding="UTF-8"
java实现在数据库中建表(mysql数据库)
public class ColumnVo { private String columnName;//字段名称 private String columnType;//字段类型 &quot;整数&quot;,&quot;小数&quot;,&quot;字符串&quot;,&quot;时间&quot; private Integer columnSize;//字段大小 private Boolean isNullable;//是否可为空 ...
相关热词 c# 线程顺序 c#昨天当前时间 c# 多进程 锁 c#mysql图片存取 c# ocx 委托事件 c# 读取类的属性和值 c# out 使用限制 c#获取url的id c#怎么进行分页查询 c# update 集合