It's not a secret anymore!*
The moose likes Tomcat and the fly likes java.io.CharConversionException when reading a string of characters from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "java.io.CharConversionException when reading a string of characters from database" Watch "java.io.CharConversionException when reading a string of characters from database" New topic
Author

java.io.CharConversionException when reading a string of characters from database

William Farrugia
Greenhorn

Joined: Apr 30, 2011
Posts: 8
Hello,

I'm running Tomcat 5 and using OpenJDK Runtime Environment (IcedTea6 1.7.10) (rhel-1.21.b17.el5-x86_64) OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode) on CentOS and recently came across one weird problem that I suspect is a JDK bug.

When I read from a mysql database, a field called randomid that is made up of a series of random characters (lower case letters, uppercase letters and numbers) such as SRM1iq1 or FRG6rx2 or XGC6gs7

I get

SEVERE: Servlet.service() for servlet jsp threw exception
java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>(SingleByteCharsetConverter.java:153)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset(SingleByteCharsetConverter.java:108)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance(SingleByteCharsetConverter.java:86)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter(ConnectionImpl.java:2767)
at com.mysql.jdbc.ResultSetRow.getString(ResultSetRow.java:754)
at com.mysql.jdbc.ByteArrayRow.getString(ByteArrayRow.java:67)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5557)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5434)
at org.apache.jsp.main_jsp._jspService(main_jsp.java:1160)
at org.apache.jasper.runtime.HttpJspBase.service(jasper5-runtime-5.5.23.jar.so)
at javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-api-5.5.23.jar.so)
at org.apache.jasper.servlet.JspServletWrapper.service(jasper5-compiler-5.5.23.jar.so)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(jasper5-compiler-5.5.23.jar.so)
at org.apache.jasper.servlet.JspServlet.service(jasper5-compiler-5.5.23.jar.so)
at javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-api-5.5.23.jar.so)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(catalina-5.5.23.jar.so)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(catalina-5.5.23.jar.so)
at org.apache.catalina.core.StandardWrapperValve.invoke(catalina-5.5.23.jar.so)
at org.apache.catalina.core.StandardContextValve.invoke(catalina-5.5.23.jar.so)
at org.apache.catalina.core.StandardHostValve.invoke(catalina-5.5.23.jar.so)
at org.apache.catalina.valves.ErrorReportValve.invoke(catalina-5.5.23.jar.so)
at org.apache.catalina.core.StandardEngineValve.invoke(catalina-5.5.23.jar.so)
at org.apache.catalina.connector.CoyoteAdapter.service(catalina-5.5.23.jar.so)
at org.apache.coyote.http11.Http11Processor.process(tomcat-http-5.5.23.jar.so)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(tomcat-http-5.5.23.jar.so)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(tomcat-util-5.5.23.jar.so)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(tomcat-util-5.5.23.jar.so)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(tomcat-util-5.5.23.jar.so)
at java.lang.Thread.run(libgcj.so.7rh)

Works perfectly on the development machine that is running Tomcat5 and a different version of JDK 6. The easy way out would be changing the JDK, but being a live running server, I'd rather think of something else.

Any ideas of how to maybe go around this problem (besides changing the random id?)

Thanks a bunch

Will
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

Looking at the stack trace, the error is nothing to do with the JDK or with the version of Tomcat. The error is that the database column in question can't be converted to chars using whatever charset is configured in MySQL and/or the Tomcat configuration and/or your Java code which sets up the database connection.

That doesn't match with your description of the field, which suggests you're just using innocuous ASCII characters, but perhaps that isn't actually the case?

Although there is this worrying line in the stack trace:
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)

which suggests that the problem might exist there...
William Farrugia
Greenhorn

Joined: Apr 30, 2011
Posts: 8
Thanks for your reply Paul.

You are right, but how do you explain the applic works on the development machine? Besides I double checked and the characters are A-Za-z0-9... so there shouldn't be any problems. The database is set to UTF in my.cnf....

not sure if this is my case http://bugs.mysql.com/bug.php?id=29636
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

You may be right... I haven't heard good things about GNU Java so perhaps it is a JDK problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.CharConversionException when reading a string of characters from database