java.sql.SQLException: Invalid argument value: java.io.NotSerializableException

展开阅读全文

使用spring SimpleJdbcTemplate遇到的问题

05-12

首先我的承认我有些画蛇添足了.但是为了尝试封装DAO,为以后遥不可及的更换DAO层做准备我做了这个尝试,结果出现问题. 我先贴一段出错的提示吧: 信息: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase] [b]org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [update res_grade_table set gradeName=:gradeName where gradeId=:gradeId]; Invalid argument value: [/b]java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 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.update(JdbcTemplate.java:786) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850) at Org.Config.DaoBaseOperation.updateByBean(DaoBaseOperation.java:37) at res.grade.Action.gradeAction.execute(gradeAction.java:46) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at Org.Config.EncodingFilter.doFilter(EncodingFilter.java:66) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source) [b]Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException[/b] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 出错的重点部分我加粗了. 我把SimpleJdbcTemplate 中的一些日常操作写到了DaoBaseOperation<E>()类中内容如下,我在gradeAction 这个类中调用updateByBean这个方法结果出现上面的错误,后面我直接使用SimpleJdbcTemplate 中的update方法错误消失(见gradeAction中注释部分),我很奇怪这个异常,传递的参数能够打印出来,可是异常却提示无效的参数值。不知道自己错在哪里。请各位朋友赐教 [code="java"] package Org.Config; import java.util.List; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; public class DaoBaseOperation<E> { static SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate( DBConnectionPool.getDataSource()); //插入数据返回数据ID public int update(String sql,E Bean){ SqlParameterSource param = new BeanPropertySqlParameterSource(Bean); KeyHolder keyHolder = new GeneratedKeyHolder(); this.simpleJdbcTemplate.getNamedParameterJdbcOperations().update(sql, param, keyHolder); return keyHolder.getKey().intValue(); } //修改或删除数据 public void updateByObjectArray(String sql,Object[] args){ this.simpleJdbcTemplate.getJdbcOperations().update(sql, args); } //修改或删除数据 public void updateByBean(String sql,E Bean){ SqlParameterSource param = new BeanPropertySqlParameterSource(Bean); System.out.println(param.getValue("gradeId")); System.out.println(param.getValue("gradeName"));//参数传递正常 this.simpleJdbcTemplate.getJdbcOperations().update(sql, param); } //查询数据 public Object find(String sql,Object[] args,Class<?> clazz){ return this.simpleJdbcTemplate.getJdbcOperations().queryForObject(sql, args, new BeanPropertyRowMapper(clazz)); } //数据列表 public List list(String sql,Object[] args,Class clazz){ return this.simpleJdbcTemplate.getJdbcOperations().query(sql, args, new BeanPropertyRowMapper(clazz)); } public List list(String sql,Class clazz){ return this.simpleJdbcTemplate.getJdbcOperations().query(sql, new BeanPropertyRowMapper(clazz)); } public List list(String sql,Object... args){ return this.simpleJdbcTemplate.queryForList(sql,args); } } [/code] [code="java"]package res.grade.Action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import res.grade.Bean.gradeBean; import Admin.AdminInfo; import Admin.BO.AdminBO; import Org.Config.DBConnectionPool; import Org.Config.DaoBaseOperation; public class gradeAction extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub ActionMessages errors = new ActionMessages(); try { AdminBO adminBO = new AdminBO(); adminBO.validateAdminSession(request); adminBO.validateModuleSession(request, AdminInfo.AdminResourcesModuleId); gradeBean gradeBean = (gradeBean) form; /*System.out.println("GradeId:"+gradeBean.getGradeId()); System.out.println("GradeName:"+gradeBean.getGradeName());*/ DaoBaseOperation<gradeBean> daobase = new DaoBaseOperation<gradeBean>(); SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate( DBConnectionPool.getDataSource()); if (gradeBean.getGradeId()==0) { daobase.update("insert into res_grade_table (gradeName) values (:gradeName)", gradeBean); } else { /*String sql = "update res_grade_table set gradeName=:gradeName where gradeId=:gradeId "; simpleJdbcTemplate.update(sql, new BeanPropertySqlParameterSource(gradeBean));*/ daobase.updateByBean("update res_grade_table set gradeName=:gradeName where gradeId=:gradeId", gradeBean); } return mapping.findForward("success"); } catch (Throwable e) { e.printStackTrace(); ActionMessage error = new ActionMessage(e.getMessage()); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } saveErrors(request, errors); return new ActionForward(mapping.getInput()); } } [/code] 问答

spring SimpleJdbcTemplate多条件查询的最佳实践.

02-21

大家好. 最近在研究jqgrid,其中牵扯到了多条件查询,而且是很高级的多条件查询. 如下图 [img]http://dl.iteye.com/upload/attachment/422393/383f4d08-c689-3219-8a37-22e66fc807b3.png[/img] 但是这就有个问题了 spring的官方文档中有查询所有字段,更新,添加 ,删除,根据某个字段进行条件查询的最佳实践例子. 但是就是没有SimpleJdbcTemplate的多条件查询字段的最佳实践例子. 目前我用到的方法如下: 随便找的一个例子 [code="java"] public List<OperatorSimple> getAllOperator(int toPage, int pageSize, String login, String name, String oper_group_id, int state) { String sql = "select p.id, p.login,p.password,p.name,p.email,p.tel,g.name,p.create_time,p.state,p.withdraw_time from oper_person_info as p " + "left join oper_group_info as g on p.oper_group_id = g.id where 1 = 1 "; Object[] params = new Object[4]; int index = 0; if (!login.equals("")) { sql += " and p.login like ? "; params[index] = login; index++; } if (!name.equals("")) { sql += " and p.name like ? "; params[index] = "%" + name + "%"; index++; } if (!oper_group_id.equals("")) { sql += " and p.oper_group_id like ? "; params[index] = oper_group_id; index++; } if (state == 1 || state == 0) { sql += " and p.state = ? "; params[index] = state; index++; } Object[] paramsEnd = new Object[index]; System.arraycopy(params, 0, paramsEnd, 0, index); int start = MysqlPaginationUtils.getStart(toPage, pageSize); sql = MysqlPaginationUtils.paginationSQLForMySQL(sql, start, pageSize); return super.getJdbcTemplate().query(sql, paramsEnd, new OperatorSimpleMapper()); }[/code] 但是这个方法我感觉好像不是最佳实践. 一来如果按照jqgrid提供的高级多条件查询,不是要写很多个if判断吗?(实际上我最高记录写了40多个...) 二来 这样也不好进行重构. 请问大家有什么好的多条件查询最佳实践吗? 问答

JSP invalid value for import请教!!

06-16

<%@ page language="java" pageEncoding="gb2312"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html locale="true"> <head> <html:base /> <title>网页主窗口</title>![ <link rel="stylesheet" type="text/css" href="CSS/style.css"> </head> <%@ include file="top.jsp" %> <body><center>图片说明](https://img-ask.csdn.net/upload/201506/16/1434443416_365534.png) <table width="1003" border="0" cellpadding="0" cellspacing="0" height="590"> <tr> <td width="202" valign="bottom"> <iframe src="left.jsp" width="100%" height="100%" frameborder="0" scrolling="auto" name="leftiframe"> </iframe> </td> <td width="801" valign="top"> <iframe src="main.jsp" width="100%" height="100%" frameborder="0" scrolling="auto" name="mainFrame"> </iframe> </td> </tr> <tr> <td height="17" valign="bottom" background="Images/left_bg_bottom.jpg"></td> <td height="17" valign="bottom" background="Images/main_bottom.jpg"></td> </tr> </table> </center> </body> </html:html> 严重: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: /default.jsp (line: 11, column: 5) Page directive: invalid value for import at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275) at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:91) at org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:325) at org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:358) at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:461) at org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1782) at org.apache.jasper.compiler.Parser.parse(Parser.java:136) at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227) at org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:117) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:580) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069) at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069) at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.struts.filter.MyFilter.doFilter(MyFilter.java:15) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:283) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2463) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2452) 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) 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览