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 <[EMAIL PROTECTED]>:

> 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:
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
> 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:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to