File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes DataSource creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DataSource creation" Watch "DataSource creation" New topic
Author

DataSource creation

chaitanya gopal
Greenhorn

Joined: May 22, 2007
Posts: 13
hi,
When i am trying to connect database using datasource it throws exception:

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

i added context to the server.xml in tomcat/ conf folder.
<Context path="/JDBCProj" docBase="JDBCProj" debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/dbconn" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/dbconn">
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbcracle:thin:@localhost:1521rcl</value>
</parameter>
<parameter>
<name>username</name>
<value>scott</value>
</parameter>
<parameter>
<name>password</name>
<value>tiger</value>
</parameter>

</ResourceParams>
</Context>


and i added reference names to web.xml as
resource name: jdbc/dbconn
resource type: javax.sql.DataSource
auth: Container

code in my JSP is:
InitialContext ctx = new InitialContext();
DataSource ds =(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/dbconn");
Connection conn = ds.getConnection();
why it throws exception?

thanks,
chaitanya.
Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
that username/password combination says you're following Bruce W. Perry's recipe ... i had a similar problem, and fixed it according to this:

http://www.johntopley.com/oldblog/kb/java/0038.html

the part that made it work:

<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>


... added at the top of the <ResourceParams> node.

good luck!
chaitanya gopal
Greenhorn

Joined: May 22, 2007
Posts: 13
Thank you for the reply paul,

i successfully connect to database using datasource-JdbcOdbcDriver
but i am trying to connect using OracleDriver it throws exception like:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:766)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at jdbcapp.CreateDatabase.doGet(CreateDatabase.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)


i added ojdbc14.jar to tomcat/common/lib folder and its there within my application.

i don't understand why it can't recognize that class.


thanks,
chaitanya.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataSource creation