A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
Solution ------ Cannot create JDBC driver of class '' for connect URL 'null'
Vasif Mustafayev
Greenhorn
Joined: Aug 07, 2010
Posts: 14
posted
Aug 08, 2010 15:32:13
0
package test.packagee; import javax.naming.*; import javax.sql.*; import java.sql.*; /* * you must copy ojdbc14.jar file into [tomcat-home]/lib add following lines into web.xml witch are in the WEB-INF folder <resource-ref> <description>Oracle Datasource</description> <res-ref-name>jdbc/myoracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> create context.xml then insert following lines and copy file into META-INF folder <?xml version='1.0' encoding='utf-8'?> <Context path="/MyFB" docBase="MyFB" crossContext="false" debug="5" reloadable="true"> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- code following is my :) --> <Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource" username="user_toad" password="user_toad" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:XE" maxActive="20" maxIdle="10" maxWait="-1"/> </Context> * */ public class java_connect_oracel_with_DataSource_using_JNDI{ private String userName= "Not get yet"; public TestConnect(){ Connection conn = null; try{ Context initContext = new InitialContext(); DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/myoracle"); conn = ds.getConnection(); System.out.println("***** Connection = "+ conn); Statement stmt = conn.createStatement(); ResultSet rst = stmt.executeQuery("select * from USERS"); if(rst.next()) { userName = rst.getString("USERNAME"); } } catch (NamingException ne) { System.out.println("NamingException "+ne.getMessage()); } catch (SQLException e) { System.out.println("SQLException "+e.getMessage()); } finally { try{ conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public String getUserName(){ return userName; } }
I spent one day for this and I get the result.
Be happy
|SCJP 6.0 80%| |SCWCD in progress|
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Aug 08, 2010 17:48:22
0
Welcome to JavaRanch!
Please
UseCodeTags
when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the
button. You're more likely to get answers the easier it is to read your messages!
I agree. Here's the link:
http://aspose.com/file-tools
subject: Solution ------ Cannot create JDBC driver of class '' for connect URL 'null'
Similar Threads
Connection pooling in tomcat
Cannot create JDBC driver of class '' for connect URL 'null'
Struts, ''dataSource'' is null
javax.servlet.ServletException: Name java: is not bound in this Context
Simple JDBC problem - Connection throws Nullpointerexception
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter