使用springjdbc提示无效的sql语句

t-sql语句拼接的方式也用了,预处理的方式也用了,但是还是抛出如下异常(在Oracle数据端能查到插入的信息):
在控制台打印的sql语句如下:
insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')

错误信息如下:
HTTP Status 500 - StatementCallback; bad SQL grammar [insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')]; nested exception is java.sql.SQLException: ORA-00900: 无效 SQL 语句

type Exception report

message StatementCallback; bad SQL grammar [insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')]; nested exception is java.sql.SQLException: ORA-00900: 无效 SQL 语句

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')]; nested exception is java.sql.SQLException: ORA-00900: 无效 SQL 语句

java 代码如下:
public class IJzxxDaoImpl implements IJzxxDao {
JdbcTemplate temp = new JdbcTemplate(DBUtil.getDs());

@Override
public int insertJzxx(Jzxx jz) {
    Integer dw_id = jz.getDw_id();
    String jz_type = jz.getJz_type();
    String jz_person = jz.getJz_person();
    Integer jz_money = jz.getJz_money();
    String jz_remark = jz.getJz_remark();
    //String sql = "insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values(?,?,?,?,sysdate,?)";
    String sql = "insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values ("+dw_id+",'"+jz_type+"','"+jz_person+"',"+jz_money+",sysdate,'"+jz_remark+"')";
    System.out.println(sql);
    return temp.queryForInt(sql);
}

各种方法试过了还是搞不定,请大家帮帮忙,谢谢!

2个回答

是我方法用错了,应该是update()方法而不是queryForInt().

仔细检查下每个字段的字段名,类型,是否少字段等

C_____Lee
LeeAtomic 将打印出来的sql语句在Oracle数据库中执行也是没有问题的
3 年多之前 回复
C_____Lee
LeeAtomic sql语句应该是没问题的,因为能够插入数据到数据库,只是页面一直在抛sql异常不知道是什么原因
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

springboot+mybatis 1.5查询一直提示无效绑定

目录结构 ![图片说明](https://img-ask.csdn.net/upload/201811/02/1541144790_912744.png)![maven配置图片说明](https://img-ask.csdn.net/upload/201811/02/1541144863_72041.png)![图片说明](https://img-ask.csdn.net/upload/201811/02/1541144949_850732.png)报错信息![图片说明](https://img-ask.csdn.net/upload/201811/02/1541145071_478503.png)daohdao.xml![![![图片说明](https://img-ask.csdn.net/upload/201811/02/1541145251_644326.png)图片说明](https://img-ask.csdn.net/upload/201811/02/1541145240_434276.png)图片说明](https://img-ask.csdn.net/upload/201811/02/1541145160_287952.png)有没有大佬帮忙解答下

Spring中JdbcTemplate执行SQL出错不回滚?

在Spring中为了方便用户对数据库的操作,Spring提供了JdbcTemplate以及HibernateTemplate。今天,查看这两个类源码,发现一问题,令我费解,请知道的朋友指点一下。 大致问题就是,在JdbcTemplate的execute(..)方法中,执行SQL抛出异常时,居然没出现回滚代码,具体代码我贴出来,方便大家参考,至于疑问,我也在代码中以注释的形式标出来了,请大家帮忙解释一下,谢谢! [code="java"]public Object execute(StatementCallback action) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); Connection con = DataSourceUtils.getConnection(getDataSource()); Statement stmt = null; try { Connection conToUse = con; if (this.nativeJdbcExtractor != null && this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativeStatements()) { conToUse = this.nativeJdbcExtractor.getNativeConnection(con); } stmt = conToUse.createStatement(); applyStatementSettings(stmt); Statement stmtToUse = stmt; if (this.nativeJdbcExtractor != null) { stmtToUse = this.nativeJdbcExtractor.getNativeStatement(stmt); } Object result = action.doInStatement(stmtToUse); //执行SQL语句 SQLWarning warning = stmt.getWarnings(); throwExceptionOnWarningIfNotIgnoringWarnings(warning); return result; } catch (SQLException ex) { /* * 加入执行SQL时抛出异常,一般来说应该回滚的,但是现在没有出现con.rollback() */ // Release Connection early, to avoid potential connection pool deadlock // in the case when the exception translator hasn't been initialized yet. JdbcUtils.closeStatement(stmt); stmt = null; DataSourceUtils.releaseConnection(con, getDataSource()); con = null; throw getExceptionTranslator().translate("StatementCallback", getSql(action), ex); } finally { JdbcUtils.closeStatement(stmt); DataSourceUtils.releaseConnection(con, getDataSource()); } }[/code] 谢谢大家耐心观看以及分析!

同一条SQL语句,myBatis查出来的数据和Navicat查出来的数据不同

通过日志打印的mybatis执行的SQL语句,原原本本复制到数据库,可以查出来很多条数据,但是mybatis要么查不到,要么少数据。 1.已尝试过写死传入参数,证明不是参数问题 2.尝试过select *,无效 3.尝试过查询的数据不小于resultMap里面的数据,也无效 4.写一个POJO类(是叫DTO吧?)来接收数据,也无效 5.SQL语句很简单,而且是通过复制到数据库,以及属性名都是通过复制,不存在写错。 走投无路了。。 以下是代码段以及日志: 日志: ``` 2018-07-02 14:05:00,244 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] 2018-07-02 14:05:00,244 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction 2018-07-02 14:05:00,244 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 2018-07-02 14:05:00,244 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 9(Integer) 2018-07-02 14:05:00,316 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <== Total: 17 2018-07-02 14:05:00,316 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] 2018-07-02 14:05:00,316 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction 2018-07-02 14:05:00,316 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 2018-07-02 14:05:00,316 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 3(Integer) 2018-07-02 14:05:00,393 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <== Total: 1143 2018-07-02 14:05:00,394 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] 2018-07-02 14:05:00,394 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction 2018-07-02 14:05:00,394 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 2018-07-02 14:05:00,394 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 2(Integer) 2018-07-02 14:05:00,472 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <== Total: 36 2018-07-02 14:05:00,472 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] 2018-07-02 14:05:00,472 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction 2018-07-02 14:05:00,472 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 2018-07-02 14:05:00,472 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 1(Integer) 2018-07-02 14:05:00,546 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <== Total: 575 ``` 以最后一条查询语句为例 : select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 参数:1 返回条数:575条 数据库数据: 594条 这是差的少的情况,差的多了,直接差了几百,一千条数据都是.. 数据库数据: ![图片说明](https://img-ask.csdn.net/upload/201807/02/1530513646_410092.png) mapper里面代码段: ![图片说明](https://img-ask.csdn.net/upload/201807/02/1530513593_738695.png)

oracle mybatis一次执行多条sql,提示SQL命令未正确结束

每条sql结尾带分号就报同样错误,单条sql的也是,不单是insert,该问题不针对insert ``` ### The error occurred while setting parameters ### SQL: alter session force parallel query parallel 8;select * from c_tbtranslateconfig where intdel=0;alter session disable parallel query; ### Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束 mybaits: mybatis-spring-boot-starter:1.3.2 oracle驱动包:com.oracle.ojdbc6:11.2.0.4 ```

java.sql.BatchUpdateException: ORA-00942: 表或视图不存在

org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update 自动生成的sql insert into "userdemo" ("name", "id") values (?, ?) hibernate最简单的save()打死不知道怎么解决,只感觉自动生成的sql语句有问题,直接运行sql语句的话报错,表名不能有“”。

关于spring jdbcTemplate中in的问题?

在用spring jdbcTemplate进行操作时,经常会用到 in .但是为什么有时候能得到真确结果,有时候不能到正确结果呢? <br /> 1. 比如如下语句 <br />    String sql = "select count(*) num from lottery_term where term_issuenum in (?) and term_lotteryid = ? and term_termstatus in (1,2)" <br />   getJdbcTemplate().queryForInt(sql,new Object[]{" '2008326','2008325','2008324' ",103}); <br />   就得不到正确的结果<br /><strong>问题补充</strong><br />兄弟我按照你的修改 可以报这个错误: <br />Caused by: java.sql.SQLException: 无效的列类型 <br />Sql中 是这样写的吗  in (?)

关于PreparedStatementSetter和jdbcTemplate.execute("insert into...")的疑问

jdbcTemplate.update("INSERT INTO USER VALUES(?, ?, ?, ?)", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, id); ps.setString(2, name); ps.setString(3, sex); ps.setInt(4, age); } }); 以上方法如果age是null如何处理 以上方法和写jdbcTemplate.execute("insert into...")有什么本质区别

在用JdbcTemplate进行插入的时候发现一个很奇怪的错误

我先用StringBuffer把sql语句拼接起来(sb="sql1;sql2;"), 再用jdbcTemplate.batchUpdate(sql);执行,数据能全部插入数据库,但是框架报了错误: org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL[Sql语句] SQL state [null]; error code [0]; An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 1; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 1 以下是sql:insert into enterarea(writeTime,commitTime,coCode,serialNumber,relTransNo,msgUid,trafMode,shipNameEn,voyageNo,billNo,orgCode,goodsNo,cargoCrossId,unitCode,quantity) values('2017-11-09 16:35:20','20171109163520','NII1X8N','NII1X8N2017110999728934377','NII1X8N2017110999728934377','','ky','','','','311010',1,'310010062810001100001','null',32)

mybatis在使用foreach进行List集合查询时,出现sql映射很多问号,不是乱码,就是多了很多问号

近日,在编写Spring Mvc的时候,出现一个特别怪的事情,我正常使用 <select id="findListWithIdsString" resultType="OrderProduct" parameterType="java.util.List"> SELECT <include refid="orderProductOwnColumns"/> a.del_flag AS "delFlag" FROM tbl_order_product a <where> a.del_flag = '0' AND a.id in ('XXXXX','XXXX') </where> </select> 这个是没问题的,但是,当我改为从java传至List的时候,就出问题了,xml代码: <select id="findListWithIdsString" resultType="OrderProduct" parameterType="java.util.List"> SELECT <include refid="orderProductOwnColumns"/> a.del_flag AS "delFlag" FROM tbl_order_product a <where> a.del_flag = '0' <choose> <when test="inComingIds != null and inComingIds.size()>0"> AND a.id in <foreach collection="inComingIds" item="item" index="index" open="(" close=")" separator="," >                  #{item}              </foreach> </when> <otherwise> AND a.id='0' </otherwise> </choose> </where> </select> 然后我的前java端代码是: List<String> idList=new ArrayList<>();//传入的List String opIds=mp.getRelatedOrderProductIds();//前端获取的String Collections.addAll(idList,StringUtils.split(opIds, ","));//转化为List OrderProduct opForSearch=new OrderProduct(); opForSearch.setInComingIds(idList); orderProductService.findListWithIdsString(opForSearch); 数据库配置如下: ?useUnicode=true&characterEncoding=utf-8 出错信息: 2019-05-01 15:28:43,034 DEBUG [modules.sys.dao.OrderProductDao.findListWithIdsString] - ==> Preparing: SELECT a.id AS "id", a.order_id AS "order.id", a.actual_flow_id AS "actualFlowId", a.category_id AS "companyCategory.id", a.parent_order_product_id as "parentOrderProductId", a.price AS "price", a.amount AS "amount", a.product_name AS "productName", a.a_product_name AS "aProductName", a.product_description AS "productDescription", a.delivery_time AS "deliveryTime", a.rate AS "rate", a.is_a_confirm AS "isAConfirm", a.confirm_userid AS "confirmUserid", a.A_confirm_time AS "aConfirmTime", a.order_product_type AS "orderProductType", a.inner_delivery_time AS "innerDeliveryTime", a.companyB_priority AS "companyBPriority", a.companyA_priority AS "companyAPriority", a.order_product_status AS "orderProductStatus", a.product_sn AS "productSn", a.a_product_sn AS "aProductSn", a.source AS "source", a.A_company_id AS "aCompany.id", a.B_company_id AS "bCompany.id", a.take_materiel_status AS "takeMaterielStatus", a.create_by AS "createBy.id", a.create_date AS "createDate", a.update_by AS "updateBy.id", a.update_date AS "updateDate", "ORDER_PRODUCT" AS "resourceType", a.remarks AS "remarks", a.down_order_status AS "downOrderStatus", a.batch_number AS "batchNumber", a.closure AS "closure", a.closure_money AS "closureMoney", a.del_flag AS "delFlag" FROM tbl_order_product a WHERE a.del_flag = '0' AND a.id in ( ???????????? ??? ? ???????? ??? , ???????????? ??? ? ???????? ??? ) 2019-05-01 15:28:43,034 DEBUG [modules.sys.dao.OrderProductDao.findListWithIdsString] - ==> Parameters: 54eca8e0409a4f5b81919ecbf7b85d44(String), 4fda20df078945aeaae3960f265795c1(String) 2019-05-01 15:28:43,094 ERROR [500.jsp] - ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??? '54eca8e0409a4f5b81919ecbf7b85d44' ???????? ??? , ?????' at line 47 ### The error may exist in D:\apache-tomcat-8.0.53-ft\webapps\blanink-web\WEB-INF\classes\mappings\modules\sys\OrderProductDao.xml ### The error may involve com.blanink.business.modules.sys.dao.OrderProductDao.findListWithIdsString-Inline ### The error occurred while setting parameters ### SQL: SELECT a.id AS "id", a.order_id AS "order.id", a.actual_flow_id AS "actualFlowId", a.category_id AS "companyCategory.id", a.parent_order_product_id as "parentOrderProductId", a.price AS "price", a.amount AS "amount", a.product_name AS "productName", a.a_product_name AS "aProductName", a.product_description AS "productDescription", a.delivery_time AS "deliveryTime", a.rate AS "rate", a.is_a_confirm AS "isAConfirm", a.confirm_userid AS "confirmUserid", a.A_confirm_time AS "aConfirmTime", a.order_product_type AS "orderProductType", a.inner_delivery_time AS "innerDeliveryTime", a.companyB_priority AS "companyBPriority", a.companyA_priority AS "companyAPriority", a.order_product_status AS "orderProductStatus", a.product_sn AS "productSn", a.a_product_sn AS "aProductSn", a.source AS "source", a.A_company_id AS "aCompany.id", a.B_company_id AS "bCompany.id", a.take_materiel_status AS "takeMaterielStatus", a.create_by AS "createBy.id", a.create_date AS "createDate", a.update_by AS "updateBy.id", a.update_date AS "updateDate", "ORDER_PRODUCT" AS "resourceType", a.remarks AS "remarks", a.down_order_status AS "downOrderStatus", a.batch_number AS "batchNumber", a.closure AS "closure", a.closure_money AS "closureMoney", a.del_flalag AS "delFlag" FROM tbl_order_product a WHERE a.del_flag = '0' AND a.id in ( ???????????? ??? ? ???????? ??? , ???????????? ??? ? ???????? ??? ) ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??? '54eca8e0409a4f5b81919ecbf7b85d44' ???????? ??? , ?????' at line 47 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??? '54eca8e0409a4f5b81919ecbf7b85d44' ???????? ??? , ?????' at line 47 org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??? '54eca8e0409a4f5b81919ecbf7b85d44' ???????? ??? , ?????' at line 47 ### The error may exist in D:\apache-tomcat-8.0.53-ft\webapps\blanink-web\WEB-INF\classes\mappings\modules\sys\OrderProductDao.xml ### The error may involve com.blanink.business.modules.sys.dao.OrderProductDao.findListWithIdsString-Inline ### The error occurred while setting parameters ### SQL: SELECT a.id AS "id", a.order_id AS "order.id", a.actual_flow_id AS "actualFlowId", a.category_id AS "companyCategory.id", a.parent_order_product_id as "parentOrderProductId", a.price AS "price", a.amount AS "amount", a.product_name AS "productName", a.a_product_name AS "aProductName", a.product_description AS "productDescription", a.delivery_time AS "deliveryTime", a.rate AS "rate", a.is_a_confirm AS "isAConfirm", a.confirm_userid AS "confirmUserid", a.A_confirm_time AS "aConfirmTime", a.order_product_type AS "orderProductType", a.inner_delivery_time AS "innerDeliveryTime", a.companyB_priority AS "companyBPriority", a.companyA_priority AS "companyAPriority", a.order_product_status AS "orderProductStatus", a.product_sn AS "productSn", a.a_product_sn AS "aProductSn", a.source AS "source", a.A_company_id AS "aCompany.id", a.B_company_id AS "bCompany.id", a.take_materiel_status AS "takeMaterielStatus", a.create_by AS "createBy.id", a.create_date AS "createDate", a.update_by AS "updateBy.id", a.update_date AS "updateDate", "ORDER_PRODUCT" AS "resourceType", a.remarks AS "remarks", a.down_order_status AS "downOrderStatus", a.batch_number AS "batchNumber", a.closure AS "closure", a.closure_money AS "closureMoney", a.del_flag AS "delFlag", a.del_flag AS "delFlag" FROM tbl_order_product a WHERE a.del_flag = '0' AND a.id in ( ???????????? ??? ? ???????? ??? , ???????????? ??? ? ???????? ??? ) ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??? '54eca8e0409a4f5b81919ecbf7b85d44' ???????? ??? , ?????' at line 47 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??? '54eca8e0409a4f5b81919ecbf7b85d44' ???????? ??? , ?????' at line 47 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) at com.sun.proxy.$Proxy27.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)

junit 测试时出错SQLException

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT PRICE FROM BOOK WHILE isbn=?]; SQL state [null]; error code [17004]; 无效的列类型; nested exception is java.sql.SQLException: 无效的列类型 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:728) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:744) at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:775) at com.cn.spring.tx.BookShopDaoImpl.findBookPriceByIsbn(BookShopDaoImpl.java:15) at com.cn.spring.tx.SpringTransactionTest.testBookShopDaoFindPriceByIsbn(SpringTransactionTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41) at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.ParentRunner.run(ParentRunner.java:220) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.sql.SQLException: 无效的列类型 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:9168) at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8749) at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9471) at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:9454) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setObject(NewProxyPreparedStatement.java:365) at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:351) at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:216) at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:144) at org.springframework.jdbc.core.ArgPreparedStatementSetter.doSetValue(ArgPreparedStatementSetter.java:65) at org.springframework.jdbc.core.ArgPreparedStatementSetter.setValues(ArgPreparedStatementSetter.java:46) at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:641) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586) ... 32 more

数据库查询字段取别名使用特殊字符

对应mysql数据库和oracle数据库查询结果字段取别名要使用特殊字符怎么处理

getHibernateTemplate()为NUll,困扰好几天了,网上也找了好些方法一直解决不掉

小弟刚刚开始学SSH,是用的Struts2+Hibernate+Spring,运行的时候发现getHibernateTemplate()得到的模板类始终是nUll值,郁闷好几天了,一直在我网上试各种方法,迄今任为解决,恳请各位指教咯! [size=large][b]applicationContext.xml:([/b]事务处理这儿没贴出来)[/size] [code="java"] <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <!-- 定义数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"> </property> <property name="url" value="jdbc:mysql://localhost:3306/jjufriend"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </bean> <!-- 定义Hibernate的sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <!-- Hibernate 的sessionFactory的属性 --> <property name="hibernateProperties"> <props> <!-- 数据库方言 --> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> <!-- 显示Hibernate持久化操作所生成的SQL语句 --> <prop key="hibernate.show_sql">true</prop> <!-- 将SQL脚本进行格式化后再输出 --> <prop key="hibernate.format_sql">true</prop> </props> </property> <!-- 列出全部的映射文件 --> <property name="mappingResources"> <list> <value>com/jjufriend/student/model/Student.hbm.xml</value></list> </property></bean> <!-- 配置dao组件 --> <bean id="studentDao" class="com.jjufriend.student.dao.impl.StudentDaoHibernate"> <!-- 依赖注入DAO组件所必需的SessionFactory引用 --> <property name="sessionFactory" ref="sessionFactory"> </property> </bean> <!-- 配置业务逻辑组件 --> <bean id="mgr" class="com.jjufriend.student.service.impl.StudentManagerImpl"> <property name="studentDao" ref="studentDao"></property> </bean> [/code] [size=large]studentDao.java:[/size] [code="java"]package com.jjufriend.student.dao; import java.util.List; import com.jjufriend.student.model.Student; public interface StudentDao { Student get(Integer id); Integer save(Student student); void update(Student student); void delete(Student student); void delete(Integer id); List<Student> findAll(); Student findStudentByNameAndPass(String username,String password); Student findByName(String username); }[/code] [size=large]StudentDaoHibernate.java:[/size] [code="java"]package com.jjufriend.student.dao.impl; import java.io.Serializable; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.jjufriend.student.dao.StudentDao; import com.jjufriend.student.model.Student; public class StudentDaoHibernate extends HibernateDaoSupport implements StudentDao,Serializable { private SessionFactory sessionFactory; HibernateTemplate ht = this.getHibernateTemplate() ; public void delete(Student student) { // TODO Auto-generated method stub getHibernateTemplate().delete(student); } public void delete(Integer id) { // TODO Auto-generated method stub getHibernateTemplate().delete(get(id)); } public List<Student> findAll() { // TODO Auto-generated method stub return (List<Student>)getHibernateTemplate().find("from Student"); } public Student findByName(String username) { List stu = getHibernateTemplate().find("from Student st where st.username = ?",username); if(stu != null && stu.size() >= 1){ return (Student)stu.get(0); } return null; } public Student findStudentByNameAndPass(String username, String password) { // TODO Auto-generated method stub List students = null; try{ // HibernateTemplate temple = this.getHibernateTemplate(); System.out.println("模板类是否为NULL>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+ht); // 取出所有 students = temple.find("from student"); students = ht.find("from student st where st.username = " + username + " and st.password = " + password); }catch(Exception e){ System.out.println("查找过程中出现异常.............."); e.printStackTrace(); } if(students != null && students.size() >= 1){ return (Student)students.get(0); } return null; } public Student get(Integer id) { return (Student)getHibernateTemplate().get(Student.class, id); } public Integer save(Student student) { return (Integer)getHibernateTemplate().save(student); } public void update(Student student) { // TODO Auto-generated method stub getHibernateTemplate().update(student); } } [/code] [size=large]StudentManager.java:[/size] [code="java"]package com.jjufriend.student.service; import com.jjufriend.student.model.Student; public interface StudentManager { int addStudent(Student student) throws Exception; int loginValid(Student student) throws Exception; boolean validateName(String username) throws Exception; } [/code] [size=large]StudentManagerImpl.java:[/size] [code="java"]package com.jjufriend.student.service.impl; import com.jjufriend.student.dao.StudentDao; import com.jjufriend.student.dao.impl.StudentDaoHibernate; import com.jjufriend.student.model.Student; import com.jjufriend.student.service.StudentManager; public class StudentManagerImpl implements StudentManager { /*2009-11-12 22:44修改 出去new StudentDaoHibernate() */ private StudentDao studentDao = new StudentDaoHibernate() ; // private ApplicationContext cxt = // new FileSystemXmlApplicationContext("../webapps/JJUFriend/WEB-INF/applicationContext.xml"); // studentDao =(StudentDaoHibernate)cxt.getBean("studentDao"); public void setStudentDao(StudentDao studentDao){ this.studentDao = studentDao ; } public int addStudent(Student student) throws Exception { // TODO Auto-generated method stub try{ studentDao.save(student); return student.getId(); }catch(Exception e){ e.printStackTrace(); throw new Exception("新增用户时出现异常"); } } public int loginValid(Student student) throws Exception { try{ System.out.println(studentDao); System.out.println("是否取到页面提交的数据:Name="+student.getUsername()); Student stu = studentDao.findStudentByNameAndPass(student.getUsername(), student.getPassword()); if(stu != null ){ return stu.getId(); } }catch(Exception e){ System.out.println("验证用户登录时出现异常"); e.printStackTrace(); } // TODO Auto-generated method stub return -1; } public boolean validateName(String username) throws Exception { // TODO Auto-generated method stub try{ if (studentDao.findByName(username) != null){ return true ; } }catch(Exception e){ System.out.println("验证用户名是否用效时出错"); e.printStackTrace(); } return false ; } } [/code] 问题的关键是通过方法getHibernateTemplate()不能正确得到HibernateTemplate对象,始终的空值,网上有很多解决的办法,差不多我都试过了, 下面这种方法是说不能直接new StudentDao对象,用下面这种方法取得,可以启动服务器老是不停地跳动,一直不停,直到报错。 [code="java"] // private ApplicationContext cxt = // new FileSystemXmlApplicationContext("../webapps/JJUFriend/WEB-INF/applicationContext.xml"); // private StudentDao studentDao =(StudentDaoHibernate)cxt.getBean("studentDao");[/code] 还有些方法是直接从applicationContext.xml中的bean取得HibernateTemplate对象,始终都搞不定,望大家指教了。 [size=medium](顶格的System.out.println()语句均是测试用的语句)[/size] [b]问题补充:[/b] 谢谢大家的热心帮助!! 确实其中出了不少问题,主要是最近网上看到解决这个方法的帖子很多,尝试过很多方法,都有点儿改晕了。 一楼的方法我尝试了,还是不行,[code="java"] private ApplicationContext cxt = this.getApplicationContext(); private StudentDao studentDao = (StudentDaoHibernate)cxt.getBean("studentDao"); [/code] 其中那个this.getApplicationContext(); 方法根本不存在啊,无法取得配置文件。 之前类似的方法我也用过就是用[code="java"] private ApplicationContext cxt = new FileSystemXmlApplicationContext("../webapps/JJUFriend/WEB-INF/applicationContext.xml"); private StudentDao studentDao =(StudentDaoHibernate)cxt.getBean("studentDao"); [/code]取得,但是当启动服务器后,后台一直跑个不停,仿佛是个死循环似的。浏览器中通过http://localhost:8080访问都无效! StudentDaoHibernate.java中的private SessionFactory sessionFactory;已经去掉 数据库方言也该过来了

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

Python可以这样学(第一季:Python内功修炼)

Python可以这样学(第一季:Python内功修炼)

C++语言基础视频教程

C++语言基础视频教程

Python可以这样学(第四季:数据分析与科学计算可视化)

Python可以这样学(第四季:数据分析与科学计算可视化)

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

Python数据分析与挖掘

Python数据分析与挖掘

微信小程序开发实战之番茄时钟开发

微信小程序开发实战之番茄时钟开发

软件测试2小时入门

软件测试2小时入门

相关热词 c# cad插入影像 c#设计思想 c#正则表达式 转换 c#form复制 c#写web c# 柱形图 c# wcf 服务库 c#应用程序管理器 c#数组如何赋值给数组 c#序列化应用目的博客园
立即提问