aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes DataSource Invalid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "DataSource Invalid" Watch "DataSource Invalid" New topic
Author

DataSource Invalid

Maryam Nouhnejad
Ranch Hand

Joined: Oct 04, 2006
Posts: 39
I'm trying to run a sample code using JNDI. (I have taken the code below from )

First I made a table in MySQL (version : MySQL 5.0.17-nt via TCP/IP) :

DROP TABLE IF EXISTS `testdata`;
CREATE TABLE `testdata` (
`ID` int(10) unsigned NOT NULL auto_increment,
`foo` varchar(25) NOT NULL default '',
`bar` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Then I added the code below to server.xml




and also added this part to WEB-INF/web.xml :


and then created a test.jsp :


I added the jar files and deployed the project and then started tomcat but when I typed this url : http://localhost:8200/JNDI/test.jsp I got this exception :
javax.servlet.jsp.JspException : Unable to get connection, DataSource invalid : "org.apache.tomcat.dbcp.dbcp.SQLNestedException : Cannot create JDBC driver of class '' for connect URL 'null' "

I added the mysql jar file; so, I don't know what can be the problem

Please help me,
Thanks in advance,
Maryam
Maryam Nouhnejad
Ranch Hand

Joined: Oct 04, 2006
Posts: 39
I have taken the code from apache.tomcat.org

please help me!
zohreh talebi
Ranch Hand

Joined: Sep 01, 2006
Posts: 41
I have this problem too. Please somebody help us.

Zohreh
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

I dont have much experience configuring datasources on Tomcat, but your server.xml doesnt look similar to what has been mentioned at the Tomcat FAQ:

Configure datasource

Look at the "MySQL DBCP Example" section for the server.xml configuration, on that page. Try changing your server.xml to match the one mentioned there.


[My Blog] [JavaRanch Journal]
zohreh talebi
Ranch Hand

Joined: Sep 01, 2006
Posts: 41
Thank you for your reply . Your blog is great.
When i run my program it gives me some exceptions from other projects too and
i check server.xml and faces-config. they were the same but i don't know why it doesn't work.

Thanks in advance,

Zohreh
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Your blog is great.

Thanks

When i run my program it gives me some exceptions from other projects too


And what are those errors? Can you post the stacktrace and a little bit more details about your application.
Michael Cook
Greenhorn

Joined: Jun 04, 2007
Posts: 5
Following the instrux at http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html I also kept getting:

org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'". I attached the stack trace below.

Anyway, I solved it by modifying the test.jsp file like this:



Here's that stack trace:



You will notice that along the way I changed "jdbc/TestDB" in the original sample to "jdbc/javatest" . My server.xml and web.xml both say the same thing in all the right places of course.
Michael Cook
Greenhorn

Joined: Jun 04, 2007
Posts: 5
P.S. I forgot to mention I am using:

- Tomcat 5.5.23
- OSX 10.4.9
- jakarta-taglibs-standard-1.1.1 (same results with 1.1.2)
- mysql-connector-java-5.0.6
- mysql-standard-5.0.24-osx10.4-powerpc
- java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164)
Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing)

I figure that Taglibs is just getting lost somewhere, but it's odd that I get the same results with 1.1.2.

I can make a stack trace for that too if it's useful.
Michael Cook
Greenhorn

Joined: Jun 04, 2007
Posts: 5
Yet another P.S. -

I was/am intrigued by this - must have read too many detective stories - lots of different Google searches turn up lots of different possible causes, such as some "connection pool" parameter called minLimit that I haven't yet located in my config so if it's there it'll be a default, also mismatching "var" in sql tags, or even omitting it, and so on.

Then I noticed in my Tomcat admin app that the JNDI Datasource in the DBTest Context has all these empty parameters:

Value
JNDI Name: jdbc/javatest
Data Source URL:
JDBC Driver Class:
User Name:
Password:
Max. Active Connections: 4
Max. Idle Connections: 2
Max. Wait for Connection: 5000
Validation Query:

So that explains the "Datasource invalid NULL" error, but why?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

I am a bit confused. Are you all running the same application and seeing this issue? If so, where did you download it from?

Michael, you mentioned that you are using jdbc/javatest. Could you post the datasource configuration file for this?
Michael Cook
Greenhorn

Joined: Jun 04, 2007
Posts: 5
Hey,

Ya - confusing is about it.

I found another better solution using Tomcat Admin meantime, but first......

To explain, we all seem to be be looking at the section "MySQL DBCP Example" in http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html, or possibly earlier versions of the same information. This is where we all seem to get our SQL to set up the "javatest" database, plus the "DBTest" Context definition, web.xml, and test.jsp. Re. my using "javatest" instead of "TestDB" I get confused when I see labels like "TestDB" and "DBTest" in the same examples, and I changed "TestDB" to "javatest" thinking it might be that simple. Otherwise everything is the same in my Context and web.inf as in the examples, or it was until....

While fiddling about with this some more (well, a LOT more):

- I got an error that my web.xml file was missing: it was and I reinstated it. This was just a user error tho'.
- Originally I had put my DBTest Context ahead of the closing Server tag in server.xml which of course is entirely the wrong place for it especially with Tomcat 5.5 and it now lives where it should under $CATALINA_HOME/conf/Catalina/localhost as DBTest.xml. At this stage it was stil the same code as the example only with "TestDB" changed to "javatest".
- At this time I noticed in Tomcat Admin that the app's Datasource was listed as a global Datasource with all fields correctly filled in, whereas the Datasource under Host/localhost-Context/DBTest was incomplete (no driver name, database URL, username or password), and I got: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver".
- I tried to fix this by creating DBTest.xml in ./conf/Catalina/localhost, and using the default server.xml at the same time. Upon restart Tomcat Admin now showed the Datasource absent from the global list and present but still incomplete under Host(localhost)/DBTest/Datasources, and I got the original "Datasource invalid ... NULL pointer" error back again.
- Next, I found that if I used Tomcat Admin to enter the missing information in the localhost/DBTest JNDI Datasource, reloaded the DBTest app from Tomcat Manager, and then ran the original test.jsp it worked properly.
- Lastly I noticed that using Tomcat Admin to "Commit changes" saved a copy of server.xml and wrote a new one as follows, after which on restart the "Datasource invalid..NULL" error was still gone with the original test.jsp now working as it should.

Here is my new server.xml:



- Last but not least, it turns out that not only was server.xml rewritten, but so were all the files in ./conf/Catalina/localhost: DBTest.xml, admin.xml, host-manager.xml, and manager.xml.

Here they all are:

New DBTest.xml:



New admin.xml:



New host-manager.xml:



New manager.xml:



Since you asked, here is my original Context ("TestDB" changed to "javatest" only):



And here is my web.xml file (same change):



Phew! Now I've written all that down I must have another cup of tea.
Michael Cook
Greenhorn

Joined: Jun 04, 2007
Posts: 5
Another P.S.

After some puzzling about where I got my "old style" Context from, it was here:

http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html

..and it lookes very similar to the document you referred to above:

http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html

Whereas this document has the "new style":

http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

... but still says to put the Context in server.xml, whereas with Tomcat 5.5 the Context can now be (should be? has to be?) in its own file $CATALINA_HOME/conf/Catalina/localhost/DBTest.xml, remembering to add the proper first line '<?xml version="1.0" encoding="UTF-8"?>'.

This probably explains where I was going wrong myself and might also explain the original one that Maryam was reporting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataSource Invalid