Results 1 to 7 of 7
- 12-30-2009, 08:57 PM #1
Member
- Join Date
- Jul 2009
- Location
- Seattle, WA
- Posts
- 23
- Rep Power
- 0
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:
Here is the JSTL code I'm using to connect and return SQL results: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
Java 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 09:01 PM.
- 01-06-2010, 07:21 PM #2
Member
- Join Date
- Jul 2009
- Location
- Seattle, WA
- Posts
- 23
- Rep Power
- 0
Can anyone shed some light on why these 'text' type columns are spitting back error messages?
- 01-06-2010, 10:00 PM #3
Member
- Join Date
- Jul 2009
- Location
- Seattle, WA
- Posts
- 23
- Rep Power
- 0
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?
- 01-07-2010, 09:05 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 01-07-2010, 09:32 AM #5
Member
- Join Date
- Jul 2009
- Location
- Seattle, WA
- Posts
- 23
- Rep Power
- 0
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.
- 01-07-2010, 09:41 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 01-07-2010, 06:04 PM #7
Member
- Join Date
- Jul 2009
- Location
- Seattle, WA
- Posts
- 23
- Rep Power
- 0
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.
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 12:29 AM.
Similar Threads
-
problem in get result than SQL to jtable
By MS_Dark in forum New To JavaReplies: 0Last Post: 12-13-2008, 12:52 PM -
Strange problem
By Tamir in forum EclipseReplies: 1Last Post: 08-18-2008, 09:44 PM -
problem with displaying result..
By SCS17 in forum New To JavaReplies: 4Last Post: 04-23-2008, 11:19 AM -
Iterating through result set in JSTL
By Java Tip in forum Java TipReplies: 0Last Post: 01-15-2008, 03:13 PM -
Iterating through result set in JSTL
By Java Tip in forum Java TipReplies: 0Last Post: 01-14-2008, 09:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks