Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-30-2009, 09:57 PM
Member
 
Join Date: Jul 2009
Location: Seattle, WA
Posts: 23
Rep Power: 0
jeremy.wilson is on a distinguished road
Question Strange JSTL recordset result problem (Question)
I have what I believe to be some rather basic JSTL code and it is returning somewhat unreadable MS SQL database results back to my pages.

Specifically, I cannot explain why the Question and or the Answer column is returning the values you see below. That is not the 'text' column type data contained in the MS SQL database.

Here is the resulting data:
Quote:
AID Question Answer Category Product dtCreated
393 net.sourceforge.jtds.jdbc.ClobImpl@2e7ace net.sourceforge.jtds.jdbc.ClobImpl@180a6ff 1 7 2009-11-06 10:09:34.92
Here is the JSTL code I'm using to connect and return SQL results:
Code:
<%@ page session="false" %>
<%@ taglib prefix="cms" uri="dubdubdub.opencms.org/taglib/cms" %>

<%@ taglib prefix="sql" uri="dubdubdub.java.sun.com/jstl/sql" %>
<%@ taglib prefix="c" uri="dubdubdub.java.sun.com/jstl/core" %>

<sql:setDataSource
  var="dataSource"
  driver="net.sourceforge.jtds.jdbc.Driver"
  url="jdbc:jtds:sqlserver://MyDBServer.somedomain.com:1433/MyDB;"
  user="user"
  password="pwd"
/>

<sql:query var="db" dataSource="${dataSource}">SELECT AID, Question, Answer, Category, Product, dtCreated FROM KB_FAQ  WHERE AID = 393</sql:query>

<table class="supporttable" border="1">

<tr>
<%-- Get the column names for the header of the table --%>
  <c:forEach var="columnName" items="${db.columnNames}">
    <td class="top"><c:out value="${columnName}"/></th>
  </c:forEach>
  </tr>

  <%-- Get the value of each column while iterating over rows --%>
  <c:forEach var="row" items="${db.rowsByIndex}">
    <tr>
      <c:forEach var="column" items="${row}">
        <td><c:out value="${column}"/></td>
      </c:forEach>
  </tr>
  </c:forEach>

</table>
<a href="#top">Back to top</a>

Last edited by jeremy.wilson; 12-30-2009 at 10:01 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-06-2010, 08:21 PM
Member
 
Join Date: Jul 2009
Location: Seattle, WA
Posts: 23
Rep Power: 0
jeremy.wilson is on a distinguished road
Default
Can anyone shed some light on why these 'text' type columns are spitting back error messages?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-06-2010, 11:00 PM
Member
 
Join Date: Jul 2009
Location: Seattle, WA
Posts: 23
Rep Power: 0
jeremy.wilson is on a distinguished road
Default
For that matter, is there any solution still using primarily JSTL, to convert the 'text' field values into something readable, or am I just better off to ask my DBA to convert all these 'text' fields into some seriously long varchar fields?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-07-2010, 10:05 AM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
Because they're Clobs. You would normally (in JDBC) use getInputStream() to read them, and stick the result into some other String (possibly). It's one of the many reasons I never do stuff like this in JSP pages. I know there's tags and all, but it's really not the place for it, IMO.

Since the stream can only be used while the resultset is open, and the resultset is closed in the sql:query tag itself, you can't access the data. There may be something in the sql taglib documentation that'll explain whether or not this is doable.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-07-2010, 10:32 AM
Member
 
Join Date: Jul 2009
Location: Seattle, WA
Posts: 23
Rep Power: 0
jeremy.wilson is on a distinguished road
Default
Well, thankfully the change from 'text' type fields to 'varchar' resolved the problem. For the amount of trouble this ultimately took to figure out and resolve, coupled with feels to me (someone with very little Java background) like a clearly lacking SQL toolset, I don't expect I'll be doing a lot of connections to our SQL database with Java. Instead I think I will opt for PHP since my past experience with it, seems like a walk in the proverbial park compared to trying to do simple select statements with either JSTL or JSP scriptlets.

Tolls, thanks for your response btw.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-07-2010, 10:41 AM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
JSP is not PHP.
Which is why I said earlier that you would not do this in a JSP page, but in a proper Java class. If you're using JSPs then you ought to have a proper setup, with Servlets, business layers, and presentation (ie JSP) layers. JSPs are only for that last bit.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-07-2010, 07:04 PM
Member
 
Join Date: Jul 2009
Location: Seattle, WA
Posts: 23
Rep Power: 0
jeremy.wilson is on a distinguished road
Default
Originally Posted by Tolls View Post
JSP is not PHP.
That much is clear. I did not intend to imply otherwise. My personal opinion in bringing up PHP at all is simply that, I as a non object-oriented programmer type, have found PHP (having now used both) to be far easier to pick up and learn than I have found to be the case with Java, and everything that goes with it, eg. classes, servlets, debugging cryptic Java runtime errors.

Originally Posted by Tolls View Post
Which is why I said earlier that you would not do this in a JSP page, but in a proper Java class.
Understood, another minor dilemma I am chewing on, primarily because of the OpenCMS layer sitting on our Debian Linux/Apache/Tomcat webserver. Truthfully I look at the use of JSTL as a crutch to help me avoid having to develop and implement classes.

Last edited by jeremy.wilson; 01-08-2010 at 01:29 AM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Tags
jstl, net.sourceforge.jtds.jdbc, sql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in get result than SQL to jtable MS_Dark New To Java 0 12-13-2008 01:52 PM
Strange problem Tamir Eclipse 1 08-18-2008 10:44 PM
problem with displaying result.. SCS17 New To Java 4 04-23-2008 12:19 PM
Iterating through result set in JSTL Java Tip Java Tips 0 01-15-2008 04:13 PM
Iterating through result set in JSTL Java Tip Java Tips 0 01-14-2008 10:31 AM


All times are GMT +2. The time now is 01:25 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org