BRabbit27
BRabbit27

Reputation: 6623

java.sql.SQLDataException: invalid month when getting data from Oracle

I've been with this exception all day and now I'm going crazy, I cannot find what's wrong in my code. I've checked and rechecked the method but I wasn't able to find a solition, I have checked and rechecked the date formats and they are all fine... Why is this sending the month invalidexception. The full stacktrace is the following, I also had found that the program throws that exception when calling ResultSet.next() method.

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)

CODE

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;
}

Upvotes: 0

Views: 6430

Answers (2)

Sajan Chandran
Sajan Chandran

Reputation: 11487

Run the following sql statement and check your NLS_DATE_FORMAT.

select * from nls_session_parameters;

The output might look like

SQL> select * from nls_session_parameters;

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_LANGUAGE                   ENGLISH
NLS_TERRITORY                  UNITED KINGDOM
NLS_CURRENCY                   £
NLS_ISO_CURRENCY               UNITED KINGDOM
NLS_NUMERIC_CHARACTERS         .,
NLS_CALENDAR                   GREGORIAN
**NLS_DATE_FORMAT                DD-MON-RR**
NLS_DATE_LANGUAGE              ENGLISH
NLS_SORT                       BINARY
NLS_TIME_FORMAT                HH24.MI.SSXFF
NLS_TIMESTAMP_FORMAT           DD-MON-RR HH24.MI.SSXFF
NLS_TIME_TZ_FORMAT             HH24.MI.SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH24.MI.SSXFF TZR
NLS_DUAL_CURRENCY              €
NLS_COMP                       BINARY
NLS_LENGTH_SEMANTICS           BYTE
NLS_NCHAR_CONV_EXCP            FALSE

17 rows selected.

Check the format of the date that you are passing to the procedure. It might solve the problem.

Upvotes: 1

Justin Cave
Justin Cave

Reputation: 231711

What is the signature of the getreportearchivo procedure? Are one or more of the parameters declared to be a DATE? If so, you should really be calling setDate rather than setString.

If all the parameters to the procedure are, in fact, VARCHAR2 parameters, do you convert the strings to dates in the procedure? If so, the format mask specified in the TO_DATE function doesn't appear to match the string that is being passed in.

Upvotes: 3

Related Questions