tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: jstl & BINARY field with mysql
Date Mon, 16 Aug 2004 14:17:13 GMT
The major difference between what JSTL does to populate the rows of the
"myQuery" variable and your scriptlet code is that JSTL uses
ResultSet.getObject while your scriptlet code uses ResultSet.getString. So, if
you change this:

String fieldValue = m_rs.getString("nick_name");
out.println(fieldValue +"<br/>");

to this:

Object fieldValue = m_rs.getObject("nick_name");
out.println(fieldValue +"<br/>");

You should see the same output.

Quoting Lorenzo Sicilia <arnor@kemen.it>:

> Hi to all,
> 
> today is my tests day :)
> 
> IN this page I make a query to mysql where the field "nick_name" is BINARY.
> With jstl I get this output:
> [B@19e681c
> [B@c50e46
> [B@12c4b66
> 
> otherwise with jsp  I get this:
> admin
> arnor
> nobody
> 
> My sql table:
> CREATE TABLE `user_comunity` (
>    `id_user` int(11) unsigned NOT NULL auto_increment,
>    `nick_name` varchar(20) binary NOT NULL default '',
>    PRIMARY KEY  (`id_user`),
>    UNIQUE KEY `nick_name` (`nick_name`)
> ) TYPE=MyIsam;
> 
> Follow the example page.
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <%@ page language="java"  import="java.sql.*" %>
> <%@ page import="javax.naming.*" %>
> <%@ page import="javax.sql.DataSource" %>
> <%@ taglib prefix="c" uri="/WEB-INF/tld/c.tld" %>
> <%@ taglib prefix="sql" uri="/WEB-INF/tld/sql.tld" %>
> 
> <sql:query var="myQuery">
> 	SELECT * FROM user_comunity
> </sql:query>
> 
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> 	<title>sql BINARY field wrong output</title>
> </head>
> <body>
> 	<!-- jstl output -->
> 	<c:forEach items="${myQuery.rows}" var="row">
> 		<c:out value="${row.nick_name}"/><br />
> 	</c:forEach>
> 	<!-- jsp output -->
> 
> <%
> 	// init connection db
> 	DataSource ds;
> 	ResultSet rs = null;
> 	Statement stmt = null;
> 	String sql = "";
> 	// search datasource
> 	 try {
> 		Context context = new InitialContext();
>   		ds = (DataSource) context.lookup("ds_croxit");
> 	 } catch (NamingException e) {
>   		ds = null;
> 	 }
> 
> 	Connection conn = ds.getConnection();
> 	ResultSet m_rs = null;
> 	PreparedStatement m_stmt = null;
> 
> 	try{
> 		// query
> 		m_stmt = conn.prepareStatement("SELECT nick_name FROM user_comunity");
> 		m_rs = m_stmt.executeQuery();
> 		// print result set
> 		while (m_rs.next() ) {
> 		// Retrieve the BINARY field
> 		String fieldValue = m_rs.getString("nick_name");
> 		out.println(fieldValue +"<br/>");
> 	}
> 	// Close
> 	m_rs.close();
> 	m_stmt.close();
> 	conn.close();
> 	}catch (Exception ex){
> 	response.getWriter().println(ex.toString());
> 	ex.printStackTrace();
> 	}
> %>
> 	</body>
> </html>
> 
> I use jrun4, jstl 1.0.5, mysql 4.0.x and sdk SunJava2-1.4.2
> 
> Can you confirm that?
> 
> regards Lorenzo Sicilia
> 
> --
> KEMEN srl
> http://www.kemen.it

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Mime
View raw message