You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Kevin Hooke <ke...@kevinhooke.com> on 2003/04/02 01:34:54 UTC

using sql:query with text columns in MySQL db

Hi - I am trying to retrieve data from a column that is defined as type
'text' in a MySQL db (I can retrieve other data ok).

The data from the 'text' columns is being returned as byte arrays, ie if I
try to display it with a <c:out> tag I get something like [B@33432223.

My sql:query looks something like this:
<sql:query var="data" dataSource="${ds}">
SELECT example_text FROM example_table
</sql:query>

And then I attempt to display the data like this:
<c:forEach var="dataItem" items="${data.rows}">
<c:out value="${dataItem.example_text}"/>
</c:forEach>

In order to get round this, I am using some scriptlet code to construct a
String instance from the byte array, like this:
    <%
    //retrieve byte[] containing column 'example_text'
    Object obj = pageContext.getAttribute("dataItem");
    TreeMap map = (TreeMap)obj;
    byte[] bChars = (byte[])map.get((Object)"example_text");
    String sText = new String(bChars);
    %>

and then output this in my JSP page like this:
    <description><%= sText %></description>

Is there an easier way to achieve this? The scriptlet code works ok, but its
a bit messy and I'd rather keep within the JSTL tags instead of having to
resort to JSP scriptlet code if it is possible.

Has anyone else had to deal with this problem if they are using text columns
with MySQL (or maybe some other column types with other DBs? If so, how did
you approach it, and do you have a simpler solution than this?

Thanks in advance,
Kevin Hooke

MindBeans Software Consulting
http://www.mindbeans.net



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org