-
1. Re: No suitable driver found for java:PostgresDS
vickyk Nov 26, 2007 7:25 AM (in response to chewbacca)javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for java:PostgresDS"
Post the complete log details .
Are you getting NoClassDefinitionError somewhere in the log ? -
2. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 7:31 AM (in response to chewbacca)Hi vickyk,
I hope that is enough. Thanks for your help!
2007-11-26 09:58:25,531 DEBUG [org.jboss.web.tomcat.service.jasper.TagLibCache] Scanning for tlds in: file:/C:/Arquivos de programas/Javaware/jboss-4.2.2.GA/server/default/deploy/jboss-web.deployer/jstl.jar
2007-11-26 09:58:27,640 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/demo].[jsp]] Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for java:PostgresDS"
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
at org.apache.jsp.demo_jsp._jspx_meth_sql_005fquery_005f0(demo_jsp.java:149)
at org.apache.jsp.demo_jsp._jspService(demo_jsp.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)
2007-11-26 09:58:46,640 DEBUG [com.arjuna.ats.arjuna.logging.arjLogger] Periodic recovery - first pass <Seg, 26 Nov 2007 09:58:46>
2007-11-26 09:58:46,640 DEBUG [com.arjuna.ats.arjuna.logging.arjLogger] StatusModule: first pass
Andre -
3. Re: No suitable driver found for java:PostgresDS
vickyk Nov 26, 2007 7:47 AM (in response to chewbacca)Andre,
Try this simple code in jsp and let me know what exception do you get<% InitialContext ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("java:PostgresDS"); Connection con = ds.getConnection(); con.close(); %>
Also make sure that you don't have any other version of postgres driver present in Jboss distribution .
Vicky -
4. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 7:55 AM (in response to chewbacca)Hi Vicky,
I am a begginer in J2EE in general, so I am having problems performing your test. I have changed my JSP page trying to do what you request, but now I am recieving the following error:
org.apache.jasper.JasperException: /demo.jsp(14,0) Invalid directive
Here is the JSP code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Test
<%@
InitialContext ctx=new InitialContext();
DataSource
ds=(DataSource)ctx.lookup( "java:PostgresDS");
Connection
con=ds.getConnection();con.close();
%>
Andre -
5. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 8:16 AM (in response to chewbacca)Hi Vicky,
I managed to run the test, and it worked. I used the follwing JSP code:
<%
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup( "java:PostgresDS");
Connection con=ds.getConnection();
System.out.println("Connection successful");
con.close();
%>
and it printed 'Connection successful' in the JBoss console window.
What does it means? That the JDBC driver is correct?
Thank you,
Andre -
6. Re: No suitable driver found for java:PostgresDS
vickyk Nov 26, 2007 8:27 AM (in response to chewbacca)
What does it means? That the JDBC driver is correct?
Yes -
7. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 8:34 AM (in response to chewbacca)Hi Vicky,
Thanks A LOT for your help. But do you know what should I try now? It is still not working.
Andre -
8. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 9:45 AM (in response to chewbacca)Hi anyone,
I'm still trying to figure it out. I will reinstate the problem now:
If I try to connect using the code below, it WORKS:
<%
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup( "java:PostgresDS");
Connection con=ds.getConnection();
con.close();
If I try to this one, it DOESN'T WORKS:
<sql:setDataSource dataSource="java:PostgresDS" />
Anyone knows why?
Thank you all,
Andre -
9. Re: No suitable driver found for java:PostgresDS
vickyk Nov 26, 2007 11:01 AM (in response to chewbacca)<sql:setDataSource dataSource="java:PostgresDS" />
Custom Tag libraries are not used properly .
You should be using it in this way<sql:setDataSource var="example" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/jboss" user="jboss" password="" />
For more details look here
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jsps/jstlsql.html
And use GOOGLE it is free :) -
10. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 11:13 AM (in response to chewbacca)Hi Vicky,
AFAIK, since I have configured the DataSource using the postgres-ds.xml in the deploy dir of JBoss, it should not be needed for me to, once again, enter the connection information (like driver, url, user and password). I should only need to refer to it using its JNDI name.
And you can be sure I googled it more than a handful of times. AAMOF, I even found the answers, but they are just not working. That is why i'm posting here.
Anyway, thanks a lot, again, for your help.
Andre -
11. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 11:29 AM (in response to chewbacca)Hi Vicky (or anyone else who is willing to help),
After testing based on the resource you provided me, the problem is even more isolated now:
If I use the code below, IT WORKS:
<sql:setDataSource var="example" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/jboss" user="jboss" password="jboss"/>
<sql:query var="qryPosts" dataSource="${example}">
SELECT postname, comments FROM public.posts
</sql:query>
When I use this code, IT DOESN'T WORK:
<sql:setDataSource var="example" dataSource="java:/PostgresDS"/>
<sql:query var="qryPosts" dataSource="${example}">
SELECT postname, comments FROM public.posts
</sql:query>
I believe the problem is the way I have configured the data source on JBoss. I probably have done something wrong, but I followinf the JBoss Getting Started guide besides other resources.
Any ideas?
Thanks again,
Andre -
12. Re: No suitable driver found for java:PostgresDS
chewbacca Nov 26, 2007 12:39 PM (in response to chewbacca)Update:
I'm realy doing something wrong. I'm getting the exact same error while trying to use MySQL...
Andre -
13. Re: No suitable driver found for java:PostgresDS
jaikiran Nov 27, 2007 3:07 AM (in response to chewbacca)"chewbacca" wrote:
When I use this code, IT DOESN'T WORK:
<sql:setDataSource var="example" dataSource="java:/PostgresDS"/>
<sql:query var="qryPosts" dataSource="${example}">
SELECT postname, comments FROM public.posts
</sql:query>
I believe the problem is the way I have configured the data source on JBoss. I probably have done something wrong, but I followinf the JBoss Getting Started guide besides other resources.
Andre,
I dont have any experience with JSTL tags, but going by what a similar post (http://forum.java.sun.com/thread.jspa?threadID=790011&messageID=9405859) says, it looks like the way the tag is interpreting the datasource JNDI name. By default, the JNDI name is bound to the java: namespace. If you want it to be available in the java:/comp/env namespace of your application(so that it can be used in the JSTL tag), then you will have to explicitly make a mention of it(using the resource-ref element) in the web.xml and jboss-web.xml.