Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Using DataSource and Creating Connection Pool

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
I have 2 problems which I think could be connected.
I am using glassfish which is JavaServerApplication 9 compliant and ( am using HSQLDB driver for database. here are the problems:
1) I can not create a connection pool using the HSQLDB driver in the GUI of asadmin> resources>jdbc>connection pool. After supplying all details and when I ping the new connection the ping fails with the message: org.hsqldb.jdbcDriver.
This is the name of the class in the driver. The jar file of the db driver is already in lib directory of glassfish/javadb. so what am I doing wrong here?

2) the second problem has to do with using DataSource to make a connection instead of Class.forName(). I am still using HSQLDB and netbeans5.5 and glassfish. now this code works fine:

Class.forName("org.hsqldb.jdbcDriver");
Connection connection = DriverManager.getConnection(url, user,password);

However when trying to use DataSource object to get a connection like this:

InitialContext ctx = new javax.naming.InitialContext();
DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/jspbook");
Connection connection = ds.getConnection();

I get the following exception:

javax.servlet.ServletException: javax.naming.NameNotFoundException: jspbook not found

And the root cause is:

javax.naming.NameNotFoundException: jspbook not found

jspbook is the name of the database.

Any idea what's wrong here?
thanks in advance
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by andre marcel:

Connection connection = DriverManager.getConnection(url, user,password);



what value your are passing in url variable?
 
andre marcel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright I managed to work around the DataSource part of the problem by using the embeded derby driver in the connection pool. I created a new data source in JDBC DataSource then did the binding in web.xml. And now I can use DataSource instead of Class.forName().
I know this might be elementary stuff to some. But I still can't add an external db driver to the connection pool and use it.
If anyone has an idea why it's such a problem or how to solve it I will appreciate their output.
thank you.
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic