pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Cannot create JDBC driver of class '' for connect URL 'null'
2+ messages / 2 participants
[nested] [flat]

* Cannot create JDBC driver of class '' for connect URL 'null'
@ 2009-03-02 15:05  Stanley Wong <wong@pcigeomatics.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Stanley Wong @ 2009-03-02 15:05 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

I encounter a problem regarding setting up a JNDI Datasource at Tomcat
with PostgreSQL under Linux Suse 10.3 environment. This is the
exception. 

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'

I wonder if there are some additional settings that I may have
forgotten. 

Would you give me a hand here?

Stanley



Here is what I do:

0) Ensure the postgreSQL.jar is stored inside the tomcat/lib 

1) Create a context.xml in the META-INF. The context.xml defines the
context below:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/someApp" docBase="someApp"
   crossContext="true" reloadable="true" debug="1">

<Resource name="jdbc/postgres" auth="Container"
          type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
          url="jdbc:postgresql://127.0.0.1:5432/testdb"
          username="gepguser" password="password" maxActive="20"
maxIdle="10"
maxWait="-1"/>
</Context> 

Where testdb is the database inside PostgreSQL.

2) Add the following entry in web.xml:

  	<resource-ref>
		<description>postgreSQL Datasource example</description>
		<res-ref-name>jdbc/postgres</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

3) Use the following code to get the connection:

	public Connection getConnection() {
		Connection conn = null;
		Context initCtx;
		try {
			initCtx = new InitialContext();
			DataSource ds = (DataSource) initCtx
	
.lookup("java:comp/env/jdbc/postgres");

			conn = ds.getConnection();
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Cannot create JDBC driver of class '' for connect URL 'null'
@ 2009-03-02 23:53  Guy Rouillier <guyr-ml1@burntmail.com>
  parent: Stanley Wong <wong@pcigeomatics.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Guy Rouillier @ 2009-03-02 23:53 UTC (permalink / raw)
  To: pgsql-jdbc

Stanley Wong wrote:
> Hi,
> 
> I encounter a problem regarding setting up a JNDI Datasource at Tomcat
> with PostgreSQL under Linux Suse 10.3 environment. This is the
> exception. 
> 
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
> driver of class '' for connect URL 'null'

Using your sample works for me with the changes indicated below.

> 
> I wonder if there are some additional settings that I may have
> forgotten. 
> 
> Would you give me a hand here?
> 
> Stanley
> 
> 
> 
> Here is what I do:
> 
> 0) Ensure the postgreSQL.jar is stored inside the tomcat/lib 
> 
> 1) Create a context.xml in the META-INF. The context.xml defines the
> context below:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Context path="/someApp" docBase="someApp"
>    crossContext="true" reloadable="true" debug="1">

Take out path and docBase.  Since you are defining a context, Tomcat 
knows those.

> 3) Use the following code to get the connection:
> 
> 	public Connection getConnection() {
> 		Connection conn = null;
> 		Context initCtx;
> 		try {
> 			initCtx = new InitialContext();
> 			DataSource ds = (DataSource) initCtx
> 	
> lookup("java:comp/env/jdbc/postgres");

You are missing a decimal point between initCtx and lookup.

Where are you running this code?  I created a sample JSP page dbtest.jsp 
and placed it in the root directory of the context.  I called my context 
text, so under that I had dbtest.jsp, META-INF and WEB-INF.  Since you 
are creating the datasource within the context, only Java code running 
within the context has access to it.

-- 
Guy Rouillier



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2009-03-02 23:53 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-03-02 15:05 Cannot create JDBC driver of class '' for connect URL 'null' Stanley Wong <wong@pcigeomatics.com>
2009-03-02 23:53 ` Guy Rouillier <guyr-ml1@burntmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox