aspose file tools*
The moose likes JSP and the fly likes IllegalStateException when inserting session attribute into a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "IllegalStateException when inserting session attribute into a table" Watch "IllegalStateException when inserting session attribute into a table" New topic
Author

IllegalStateException when inserting session attribute into a table

Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Hi ,
Actually i am working on a project on Online Job Portal . In that , i get an exception in Job Seeker Login servlet . Here are the following codes for the reference .

JsLoginProcess.java ( Job Seeker Login Servlet Code)




After i try to login as a Jobseeker , i am getting the following exception from the Login Servlet that i posted above.

Exceptions

WARNING: StandardWrapperValve[JsLoginProcess]: PWC1406: Servlet.service() for servlet JsLoginProcess threw exception
java.lang.IllegalStateException: PWC1227: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:370)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)
at com.JsLoginProcess.processRequest(JsLoginProcess.java:60)
at com.JsLoginProcess.doGet(JsLoginProcess.java:79)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)

Applyjob.jsp ( The jsp file to Insert the Job Applied into the Applyjob table)


After Clicking the ApplyJob button of Applyjob.jsp , i am getting the following exception :

JSP Exceptions

SEVERE: java.sql.SQLDataException: A truncation error was encountered trying to shrink VARCHAR 'murali@gmail.com' to length 10.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Statement.executeUpdate(Unknown Source)
at org.apache.jsp.Applyjob_jsp._jspService(Applyjob_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.derby.client.am.SqlException: A truncation error was encountered trying to shrink VARCHAR 'murali@gmail.com' to length 10.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.am.Statement.completeExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.StatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(Unknown Source)
at org.apache.derby.client.am.Statement.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.am.Statement.flowExecute(Unknown Source)
at org.apache.derby.client.am.Statement.executeUpdateX(Unknown Source)
... 33 more

SEVERE: at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
SEVERE: at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
SEVERE: at org.apache.derby.client.am.Statement.executeUpdate(Unknown Source)
SEVERE: at org.apache.jsp.Applyjob_jsp._jspService(Applyjob_jsp.java:71)
SEVERE: at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
SEVERE: at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
SEVERE: at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
SEVERE: at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
SEVERE: at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
SEVERE: at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
SEVERE: at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
SEVERE: at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
SEVERE: at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
SEVERE: at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
SEVERE: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
SEVERE: at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
SEVERE: at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
SEVERE: at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
SEVERE: at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
SEVERE: at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
SEVERE: at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
SEVERE: at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
SEVERE: at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
SEVERE: at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
SEVERE: at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
SEVERE: at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
SEVERE: at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
SEVERE: at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
SEVERE: at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
SEVERE: at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
SEVERE: at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
SEVERE: at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
SEVERE: at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
SEVERE: at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
SEVERE: at java.lang.Thread.run(Thread.java:722)
SEVERE: Caused by: org.apache.derby.client.am.SqlException: A truncation error was encountered trying to shrink VARCHAR 'murali@gmail.com' to length 10.
SEVERE: at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
SEVERE: at org.apache.derby.client.am.Statement.completeExecuteImmediate(Unknown Source)
SEVERE: at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(Unknown Source)
SEVERE: at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(Unknown Source)
SEVERE: at org.apache.derby.client.net.StatementReply.readExecuteImmediate(Unknown Source)
SEVERE: at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(Unknown Source)
SEVERE: at org.apache.derby.client.am.Statement.readExecuteImmediate(Unknown Source)
SEVERE: at org.apache.derby.client.am.Statement.flowExecute(Unknown Source)
SEVERE: at org.apache.derby.client.am.Statement.executeUpdateX(Unknown Source)
SEVERE: ... 33 more



So i am not able to proceed the codings without overcoming the above Exception . Hence it would be really great if you help me overcome the above Exceptions. . Kindly let me know if i need put any of my other codings for further reference .

Thanks A Lot in Advance !!


Regards,
Kasiraj
Shrivastava Amit
Greenhorn

Joined: Jan 31, 2008
Posts: 7
Try with below code :



Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
>SEVERE: java.sql.SQLDataException: A truncation error was encountered trying to shrink VARCHAR 'murali@gmail.com' to length 10.

This error seems obvious enough.
The database field you are storing the email address to allows only 10 characters.
So take a look at the App.ApplyJob table and see that you are inserting into the correct column, and that column is large enough to store values in.

Other tips
- Java code belongs in servlets, not in JSPs.
- Use prepared statements rather than constructing SQL strings. You are opening yourself up to SQL Injection attacks.
- Use a JNDI Datasource to obtain database connections rather than making a database connection yourself.

Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Stefan Evans wrote:>SEVERE: java.sql.SQLDataException: A truncation error was encountered trying to shrink VARCHAR 'murali@gmail.com' to length 10.

This error seems obvious enough.
The database field you are storing the email address to allows only 10 characters.
So take a look at the App.ApplyJob table and see that you are inserting into the correct column, and that column is large enough to store values in.

Other tips
- Java code belongs in servlets, not in JSPs.
- Use prepared statements rather than constructing SQL strings. You are opening yourself up to SQL Injection attacks.
- Use a JNDI Datasource to obtain database connections rather than making a database connection yourself.



Thanks A Lot Mr.Stefan Evans !!! . . That really helped a lot . . Just realized it was a silly mistake that i made in interchanging the values for 2 rows and tried to insert the emailid to a row where the limit is 10 rather than inserting it in the row where limit is 30 . Anyhow got it fixed now. And thanks again for your Tips . . I hope to follow all of those in my later projects . .

Thanks Once Again !!!

Regards,
Kasiraj Murugesapandian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException when inserting session attribute into a table
 
Similar Threads
JasperReport error while connecting from Struts action class
Exception when i am trying to dispatch the request to a Error Page
Exception executing servlet with database connectivity
PWC1406: Servlet.service() for servlet threw exception:java.io.FileNotFoundException
Problem in delete form