java.sql.SQLException: 列名无效

select deptno,dname,dtype,dphone,dfax,ddescription,dupper,dcreatedate from dept where deptno=1

SQL语句在PLSQL下执行没有问题,但是放在程序中报下面的错。

if (rs.next()) {
dept.setDeptNo(rs.getInt("deptno"));
dept.setDeptName(rs.getString("dname"));
dept.setDeptType(rs.getString("dtype"));
dept.setDeptPhone(rs.getString("dphone"));
dept.setDeptFax(rs.getString("dfax"));
dept.setDeptDescription(rs.getString("ddescription"));
dept.setDupper(rs.getInt("dupper"));
dept.setDeptCreateDate(rs.getString("DCreateDate"));
}

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.OracleStatement.getColumnIndex(OracleStatement.java:3296)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263)
at com.neusoft.hr.model.dao.impl.DeptInfoDaoImpl.findDeptByID(DeptInfoDaoImpl.java:182)
at com.neusoft.hr.model.service.DeptService.findDeptById(DeptService.java:104)
at org.apache.jsp.view.dept_005fpost.deptmod_jsp._jspService(deptmod_jsp.java:112)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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 com.neusoft.hr.utils.EncodingFilter.doFilter(EncodingFilter.java:29)
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:127)
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:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)

at java.lang.Thread.run(Thread.java:619)


把语句注释之后没有问题,后来经过排查,原来是对数据库中的date字段处理不当

把dept.setDeptCreateDate(rs.getString("DCreateDate"));改成dept.setDeptCreateDate(rs.getDate("DCreateDate").toString());以后问题随之解决。(PS:为了方便处理,我在程序中对日期用STRING类型处理,进行数据库插入,更新操作的时候用to_date()转换)

你可能感兴趣的:(sql,数据库,Date,String)