- This topic has 11 replies, 2 voices, and was last updated 19 years, 5 months ago by Riyad Kalla.
-
AuthorPosts
-
Bala DatlaMemberHi,
I am getting the following error while running the tomcat from eclipse(Myeclipse).
Cannot create JDBC driver of class ” for connect URL ‘null’
If I run tomcat in command line its working fine.
please advice me.
Here is the environment :
Windows XP
eclipse 3.0.2
myeclipse work bench V3.8.4
Riyad KallaMemberWhat is the entire console message when you try and startup Tomcat?
Bala DatlaMemberI I have written startup servlet and startup servlet get the some data from oracle and kept into memory.
The code of DataInfo.java:98 is
connection = ds.getConnection();
at com.test.util.loadData(DataInfo.java:98)Here is the stack trace.
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class ” for connect URL ‘null’, cause:
java.lang.NullPointerException
at oracle.jdbc.driver.OracleDriver.oracleAcceptsURL(OracleDriver.java:282)
at oracle.jdbc.driver.OracleDriver.acceptsURL(OracleDriver.java:316)
at java.sql.DriverManager.getDriver(DriverManager.java:232)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:743)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
at com.test.util.loadData(DataInfo.java:98)
at com.test.startup.startup(Startup.java:595)
at com.manheim.mims.core.control.web.MainServlet.init(MainServlet.java:76)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:888)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:776)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3363)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3586)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1141)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:707)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1141)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:316)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2143)
at org.apache.catalina.startup.Catalina.start(Catalina.java:463)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:350)
at org.apache.catalina.startup.Catalina.process(Catalina.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:156)
java.lang.NullPointerException
at com.test.util.loadData(DataInfo.java:171)
at com.test.startup.startup(Startup.java:595)
at com.test.core.control.web.MainServlet.init(MainServlet.java:76)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:888)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:776)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3363)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3586)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1141)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:707)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1141)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:316)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2143)
at org.apache.catalina.startup.Catalina.start(Catalina.java:463)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:350)
at org.apache.catalina.startup.Catalina.process(Catalina.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:156)
Riyad KallaMemberMoving to OT > Soft DEv, this is not a MyEclipse issue.
Secondly, I would suggest you take a look at your code around this line (or post the entire method here):
at com.test.util.loadData(DataInfo.java:98)
Bala DatlaMemberThe code at com.test.util.loadData(DataInfo.java:98) is
Connection connection = ds.getConnection();The error is comming If I ran the server from Myeclipse environment.
I am not getting this error if I export the war file into tomcat server and run the server from command line.(not in eclipse environment);
Riyad KallaMemberConnection connection = ds.getConnection();
Please paste the whole method, the problem is with how your data source is configured, somethignw rong with the connection string looking at your exception. How have you set this data source up? What is different between how you launch Tomcat externally and how you launch it from MyEclipse? How DO you launch it externally? Batch file? System service? Did you modify the startup scripts? etc. etc.
Bala DatlaMemberI am running the tomcat through batch file given by the tomcat(startup.bat) I did not done any modifications in startup.bat.
In myEclipse setup.
windows–>preferences–>myEclipse–>applicatopn servers
–>tomcat 4after setup I am running the tomcat
Deploy J2ee project to Server
running the server from Run/stop server tool bar.
Here is class .
package com.xxx.xxx.xx.util;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.SQLException;import javax.naming.*;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import xxxxxxxxx.control.JNDINames;/**
* This class gets Info data info from the Oracle db
*
*/
public class DataInfo {/**
* DataInfo constructor.
*/
public DataInfo() {
}/**
* This method loads up the auction data from the Oracle db
* @return boolean
* @param none
*/
public boolean loadData(InitialContext ctx, String application) {
//String driver = System.getProperty(“driver”);
//String url = System.getProperty(“url”);
DataSource ds;
Connection connection;if (System.getProperty(application + “.test”).equals(“true”))
{
System.out.println(“LOADING Data \n\n”);
DataSite dataSite = new DataSite ()
dataSite.setDataName(“TEST”);
dataSite.setAddress1(“ffff”);
dataSite.setCity(“fffff”);
dataSite.setState(“ff”);
dataSite.setZip(“33333”);
dataSite.setDataPhoneNbr(“555 555-1234”);
dataSite.setEmail(“aaa@xxxxxx.com”);
dataSite.setDataShortName(“ddddd.”);
dataSite.setDataId(“AAg”);
Constants.dataData.put(“AAg”, dataSite);dataSite = new DataSite();
dataSite.setDataName(“cvxcvxv”);
dataSite.setAddress1(“333 Second”);
dataSite.setCity(“abc”);
dataSite.setState(“atl”);
dataSite.setZip(“44444”);
dataSite.setAuctionPhoneNbr(“999 555-1234”);
dataSite.setEmail(“faao@xxxx.com”);
dataSite.setAuctionShortName(“cccccc”);
dataSite.setAuctionId(“CADE”);
Constants.dataData.put(“CADE”, dataSite);dataSite = new DataSite();
dataSite.setDataName(“ssssssss”);
dataSite.setAddress1(“333 RRRR”);
dataSite.setCity(“ffff”);
dataSite.setState(“fff”);
dataSite.setZip(“222”);
dataSite.setDataPhoneNbr(“999 511-1114”);
dataSite.setEmail(“faao@xxxx.com”);
dataSite.setDataShortName(“xxxxxxx”);
dataSite.setDataId(“ASF”);
Constants.dataData.put(“ASF”, dataSite);return true;
}
else
{
try {
ds = (DataSource) ctx.lookup(java:comp/env/jdbc/MDataSource);
//ds = (DataSource) ctx.lookup(“jdbc/OracleDS”);
connection = null;
} catch (NamingException ne) {
String errMsg = “DATABASE ERROR – Naming Exception >>>>>> Can’t find datasource”;
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
ne.printStackTrace();
return false;
}try {
//Class.forName(driver);
//connection = DriverManager.getConnection(url, System.getProperty(“dbuser”), System.getProperty(“dbpassword”));
connection = ds.getConnection();
checkForWarnings(connection.getWarnings());
Statement curStmt = connection.createStatement();
//Create the sql string
String query = “select * from datas”;
ResultSet rs = curStmt.executeQuery(query);
checkForWarnings(connection.getWarnings());
while (rs.next())
{
DataSite dataSite = new DataSite();
dataSite.setDataName(rs.getString(2));
dataSite.setAddress1(rs.getString(3));
dataSite.setAddress2(rs.getString(4));
dataSite.setCity(rs.getString(5));
dataSite.setState(rs.getString(6));
dataSite.setZip(rs.getString(7));
dataSite.setDataPhoneNbr(rs.getString(8));
dataSite.setFaxNbr(rs.getString(9));
dataSite.setEmail(rs.getString(13));
dataSite.setDataShortName(rs.getString(14));
dataSite.setDataId(rs.getString(1));
String site = (String)Constants.dataMap.get(rs.getString(1));
if (site != null)
{
dataSite.setDataHasURL(true);
}Constants.dataData.put(rs.getString(1), dataSite);
}
curStmt.close();
} catch (SQLException sqlx) {
String errMsg = “DATABASE ERROR – SQL Exception >>>>>> Trying to get data data”;
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
sqlx.printStackTrace();
return false;
} catch (Exception e) {
String errMsg = “DATABASE ERROR – Exception >>>>>> Trying to get data data”;
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
e.printStackTrace();
return false;
} finally {
try {
connection.close();
return true;
} catch (SQLException sqlx) {
String errMsg = “DATABASE ERROR – SQL Error Can’t close connection >>>>>>”;
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
System.out.println(errMsg);
sqlx.printStackTrace();
return false;
}
}
}
}
}
Riyad KallaMemberI don’t see how this code you pasted compiled, you don’t have your data source as a String:
ds = (DataSource) ctx.lookup(java:comp/env/jdbc/MDataSource);
Let’s assume there was a problem with pasting it and you do though, in that case, how do you have this data source setup in Tomcat? Which file did you modify to set it up?
Bala DatlaMemberdont look at the sytax level as I have changed the names and values for sucurity reasons. You need to assume the code does not have any compilation problems.
Riyad KallaMemberI understand that, please read the 2nd sentence from my post above.
Bala DatlaMemberI have done datasource setup in server.xml and I copied the required jar /zip file for oracle driver in commom/lib directory of TOMCAT_HOME.( And also copied all lib directories and tested no difference)
here is the server.xml entry
<Context className=”org.apache.catalina.core.StandardContext” cachingAllowed=”true” charsetMapperClass=”org.apache.catalina.util.CharsetMapper” cookies=”true” crossContext=”false” debug=”2″ displayName=”saas” docBase=”saas” mapperClass=”org.apache.catalina.core.StandardContextMapper” path=”/datatest” privileged=”false” reloadable=”false” swallowOutput=”false” useNaming=”true” workDir=”work\Standalone\localhost\datatest” wrapperClass=”org.apache.catalina.core.StandardWrapper”><Resource name=”jdbc/MDataSource” scope=”Shareable” type=”javax.sql.DataSource”/>
<ResourceParams name=”jdbc/MDataSource”>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@hostname:1521:testdev</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>username</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams></Context>
Riyad KallaMemberThe basic problem here is that there is some setup of Tomcat that we so far haven’t simulated with the Tomcat 4 connector yet, so let me walk through a few things that you can double check.
1) From this page http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html it seems if you want to use the OCI driver, there are also DLLs that you will need to place into your library path. Are you using the OCI driver? If you are, then you need to add the directory that contains the DLLs via the Tomcat 4 > Paths settings, in the last box “Append to Library Path”.
2) If you are using the thin driver, then the only things you should need to do are:
a) Copy the driver into common/lib
b) Setup your context
c) Deploy your applicationYou shouldn’t need to mess with ANY of the Tomcat 4 > Paths settings, have you adjusted these in any way? Added any JARs?
3) Startup Tomcat from the command line, load up the Tomcat administrator, login and go to your Data Source, can you see it?
4) Now startup Tomcat from MYEclipse, also login to the Tomcat Administrator and go to the Data Source, can you still see it?
5) Do you have a /META-INF/context.xml file in your project? If so, what are it’s contents.
-
AuthorPosts