It's not a secret anymore!*
The moose likes Tomcat and the fly likes when reading a string of characters from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark " when reading a string of characters from database" Watch " when reading a string of characters from database" New topic
Author when reading a string of characters from database

William Farrugia

Joined: Apr 30, 2011
Posts: 8

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
at java.lang.String.init(
at java.lang.String.<init>(
at com.mysql.jdbc.SingleByteCharsetConverter.<init>(
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset(
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance(
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter(
at com.mysql.jdbc.ResultSetRow.getString(
at com.mysql.jdbc.ByteArrayRow.getString(
at com.mysql.jdbc.ResultSetImpl.getStringInternal(
at com.mysql.jdbc.ResultSetImpl.getString(
at org.apache.jsp.main_jsp._jspService(
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
at org.apache.tomcat.util.threads.ThreadPool$

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

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

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:

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

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
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

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:
subject: when reading a string of characters from database
Similar Threads
not able to run two site simultaneously in a tomcat websrever
ServletException: Error allocating a servlet instance
Problem grabbing RSS from a website and displaying it from servlet
Marking servlet HelloWorld as unavailable
Trouble Installing JForum on VPS