从Oracle获取数据时的月份无效

从Oracle获取数据时的月份无效

我整天都在遇到这种异常,现在我快要疯了,我找不到我的代码有什么问题。我已经检查并重新检查了该方法,但是我找不到一个孤立的地方,我已经检查并重新检查了日期格式,它们都很好...为什么发送month invalid异常。完整的堆栈跟踪如下,我还发现调用ResultSet.next()方法时程序会抛出该异常。

feb 27, 2012 4:03:38 PM mx.gob.sagarpa.utilidades.Database generarReporteArchivos
SEVERE: null
java.sql.SQLDataException: ORA-01843: not a valid month

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
        at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
        at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
        at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
        at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1108)
        at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:373)
        at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:
277)
        at mx.gob.sagarpa.utilidades.Database.generarReporteArchivos(Database.ja
va:160)
        at mx.gob.sagarpa.beans.TableBean.generarReportes(TableBean.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:2
78)
        at org.ajax4jsf.component.behavior.MethodExpressionAjaxBehaviorListener.
processAjaxBehavior(MethodExpressionAjaxBehaviorListener.java:71)
        at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent
.java:113)
        at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.ja
va:106)
        at org.ajax4jsf.component.behavior.AjaxBehavior.broadcast(AjaxBehavior.j
ava:291)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:
760)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)

        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
259)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicat
ionPhase.java:81)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:169)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
929)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:405)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:964)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:515)
        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
t.java:1824)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:603)
        at java.lang.Thread.run(Thread.java:722)




public List<RegistroReporteArchivo> generarReporteArchivos(
        int idUsuario, String nombreArchivo,
        String fechaInicio, String fechaFin) {
    CallableStatement cs;
    ResultSet rs = null;
    List<RegistroReporteArchivo> list = new ArrayList<RegistroReporteArchivo>();
    try {
        connect();
        cs = connection.prepareCall("{call getreportearchivo(?,?,?,?,?)}");
        cs.setInt(1, idUsuario);
        cs.setString(2, nombreArchivo);
        cs.setString(3, fechaInicio);
        cs.setString(4, fechaFin);
        cs.registerOutParameter(5, OracleTypes.CURSOR);
        cs.execute();
        rs = (ResultSet) cs.getObject(5);
        while (rs.next()) {  //The exception marks this line as the responsible !!
            list.add(new RegistroReporteArchivo(rs.getString(1),
                    rs.getInt(2), rs.getInt(3), rs.getInt(4),
                    rs.getInt(5)));
        }
        disconnect();
    } catch (SQLException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    }
    return list;
}

最佳答案

getreportearchivo过程的签名是什么?是否将一个或多个参数声明为DATE?如果是这样,则您实际上应该在调用setDate而不是setString

如果该过程的所有参数实际上都是VARCHAR2参数,您是否将字符串转换为该过程中的日期?如果是这样,则TO_DATE函数中指定的格式掩码似乎与传递的字符串不匹配。

关于java - java.sql.SQLDataException:从Oracle获取数据时的月份无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9473273/

10-10 03:23