Thread: java.sql.* works, JSTL:SQL does not ?

java.sql.* works, JSTL:SQL does not ?

From
Steffen Neumann
Date:
Hi,

I am having a problem getting JSP pages with JSTL SQL
connecting to PostgreSQL to work in JDeveloper/OC4J.

I do have a working setup connecting to postgres
from a plain JSP page, as well as connecting
to an Oracle server from both JSTL SQL and plain JSP.
The JSP pages are at the end of this mail.

I tried several URLs, like
    url="jdbc:postgresql://localhost:5432/tea"
    url="jdbc:postgresql:tea"
to no avail.

What could be the difference between the hand-created Connection
and the JSTL variant ? What could be the difference between
the postgresql.jar and the oracle JDBC driver that makes the
latter work in my setup ? The postgresql.jar is taken from libpgjava
in Debian and has been compiled with JDK 1.4 package from Blackdown

Postgresql is 7.4.5-3 (Debian), using postgresql-jdbc[23]-7.4.2.jar,
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)

Hope there is someone out who could help,
yours,
Steffen


============================================================================
This code works fine in my setup and delivers the results:

<%@ page contentType="text/html;charset=US-ASCII"
import="java.sql.*"%>

<%
    Class.forName("org.postgresql.Driver");
    Connection con = DriverManager.getConnection("jdbc:postgresql:tea", "myusername", "mypassword");
%>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>untitled</title>
  </head>
  <body>
<%
    Statement  stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select * from fgroup");
    while (rs.next()) {
    %>
    <%=rs.getString("gname")%>
    <%
    }
%>
  </body>
</html>
---------------------------------------------------------------------

This code gives an JspException

<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
<%@ page contentType="text/html;charset=US-ASCII"%>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>untitled</title>
  </head>
  <body>

    <sql:setDataSource
    url="jdbc:postgresql://localhost:5432/tea"
    driver="org.postgresql.Driver"
    user="myusername" password="mypassword" />

(untitled1.jsp:16)  <sql:query var="news">
        SELECT gname FROM fgroup
    </sql:query>
    </body>
</html>

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "No suitable driver"
    at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:308)
    at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:192)
    at org.apache.taglibs.standard.tag.el.sql.QueryTag.doStartTag(QueryTag.java:125)
    at _untitled1._jspService(untitled1.jsp:16)
    [/untitled1.jsp]
    at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:349)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    at com.evermind[Oracle Application Server Containers for J2EE 10g
(9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    at java.lang.Thread.run(Thread.java:534)

---------------------------------------------------------------------

This code works fine in my setup and delivers the results:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
<%@ page contentType="text/html;charset=US-ASCII"%>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>untitled</title>
  </head>
  <body>

  <sql:setDataSource
    dataSource="jdbc:oracle:thin:@my.host.de:1521:SID,oracle.jdbc.driver.OracleDriver,myusername,mypassword" />

  <sql:query var="genes">
        SELECT gid, gname FROM fgroup
    </sql:query>

  <table width="100%">
<%-- Get the column names for the header of the table --%>
<c:forEach var="columnName" items="${genes.columnNames}">
  <th><c:out value="${columnName}"/></th>
</c:forEach>

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



Re: java.sql.* works, JSTL:SQL does not ?

From
Steffen Neumann
Date:
Hi, just to follow up my own post:
Steffen Neumann <sneumann@techfak.uni-bielefeld.de> writes:
[...]
> What could be the difference between the hand-created Connection
> and the JSTL variant ? What could be the difference between
> the postgresql.jar and the oracle JDBC driver that makes the
> latter work in my setup ? The postgresql.jar is taken from libpgjava
> in Debian and has been compiled with JDK 1.4 package from Blackdown
I now also tried the following clients: from jdbc.postgresql.org
the two variants pg74 jdbc2+j2ee and jdbc3, as well as the beta 8.0
jars. And from Redhat the rh-postgresql3.jar.

Apart from the jdeveloper embedded OC4J I get the same results
from SUNWappserver 8 2004q4, with the same result.

Any tips where to continue ?

Yours,
Steffen



Re: java.sql.* works, JSTL:SQL does not ?

From
Dave Cramer
Date:
Steffan,

Looking at your code I don't see any problems, you may have to dig into the taglibs code.

Dave

Steffen Neumann wrote:
Hi, just to follow up my own post:
Steffen Neumann <sneumann@techfak.uni-bielefeld.de> writes:
[...] 
What could be the difference between the hand-created Connection
and the JSTL variant ? What could be the difference between
the postgresql.jar and the oracle JDBC driver that makes the 
latter work in my setup ? The postgresql.jar is taken from libpgjava
in Debian and has been compiled with JDK 1.4 package from Blackdown   
I now also tried the following clients: from jdbc.postgresql.org
the two variants pg74 jdbc2+j2ee and jdbc3, as well as the beta 8.0
jars. And from Redhat the rh-postgresql3.jar.

Apart from the jdeveloper embedded OC4J I get the same results
from SUNWappserver 8 2004q4, with the same result. 

Any tips where to continue ?

Yours,
Steffen



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

 

-- 
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561