cormierg1
asked on
Datasource in Tomcat
Can anyone help me create a datasource in Tomcat? I'm running version 5.5.9, the one included with Netbeans 5.0
I've followed http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
Here's my server.xml
<Resource name="jdbc/publicommon" auth="Container"
type="javax.sql.DataSource " driverClassName="oracle.jd bc.OracleD river"
url="jdbc:oracle:thin:@pea nut:1521:p ad"
username="***" password="***" maxActive="20" maxIdle="10"
maxWait="-1"/>
My web.xml
<resource-ref>
<description>PCT Datasource</description>
<res-ref-name>jdbc/publico mmon</res- ref-name>
<res-type>javax.sql.DataSo urce</res- type>
<res-auth>Container</res-a uth>
</resource-ref>
Yet I still get
java.lang.ExceptionInIniti alizerErro r: Could not find datasource
Honestly, if I could line up the tomcat devs......... it's unreal trying to get this thing working.
I've followed http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
Here's my server.xml
<Resource name="jdbc/publicommon" auth="Container"
type="javax.sql.DataSource
url="jdbc:oracle:thin:@pea
username="***" password="***" maxActive="20" maxIdle="10"
maxWait="-1"/>
My web.xml
<resource-ref>
<description>PCT Datasource</description>
<res-ref-name>jdbc/publico
<res-type>javax.sql.DataSo
<res-auth>Container</res-a
</resource-ref>
Yet I still get
java.lang.ExceptionInIniti
Honestly, if I could line up the tomcat devs......... it's unreal trying to get this thing working.
How do you retrieve the datasource? Try changing the name to somethign that does not contain / and try again
ASKER
It's with Hibernate.
String datasourceName = "jdbc/publicommon";
toolConfiguration.setPrope rty("hiber nate.conne ction.data source", datasourceName);
I've had no issues with the slash in Websphere, and all the online documents use one as well..
String datasourceName = "jdbc/publicommon";
toolConfiguration.setPrope
I've had no issues with the slash in Websphere, and all the online documents use one as well..
Ok I see. Your config code looks file. What is the toolConfiguration?
Are you coding doing this manually? Netbeans will generate all the code you need to make the connection, if thats any use. As long as you have the datasource listed in the runtime panel, then right click in your source code and select 'use datasource' or something like that.
ASKER
Yes, I am coding all of this manually.
Could you try doing it via netbeans and check the code it produces? Its quite concise, so its a good starting point to have a working version. In future projects, youll find it a lot easier using netbeans to do this kind of plumbing for you anyway. When I started with this kind of stuff I found myself banging my head against my desk so often, because I couldnt get the 'simple' examples to work. In the end I started using the automated tools via the IDE I was using - the time I spent banging my head made me understand enough about the whole process in general though to go in and make changes to the XML etc.
ASKER
How do I do this?
Under runtime I've added my Oracle driver, and added a database to my database tab but I see no option to include it as a datasource.
Under runtime I've added my Oracle driver, and added a database to my database tab but I see no option to include it as a datasource.
ASKER
I might be one step closer...
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.get Driver(Dri verManager .java:243)
at org.apache.tomcat.dbcp.dbc p.BasicDat aSource.cr eateDataSo urce(Basic DataSource .java:773)
... 26 more
Where do I put my ojdbc14.jar? I tried
netbeans/enterprise2/jakar ta-tomcat- 5.5.9/comm on/lib
and
netbeans/enterprise2/jakar ta-tomcat- 5.5.9/serv er/lib
but it still doesn't pick it up?
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.get
at org.apache.tomcat.dbcp.dbc
... 26 more
Where do I put my ojdbc14.jar? I tried
netbeans/enterprise2/jakar
and
netbeans/enterprise2/jakar
but it still doesn't pick it up?
Try a different driver. The ojdbc is probably for the odbc bridge.
ASKER
No, ojdbc14.jar is the Oracle JDBC driver.
ojdbc14.jar
Classes for use with JDK 1.4. It contains the JDBC driver
classes, except classes for NLS support in Oracle Object and
Collection types.
ojdbc14.jar
Classes for use with JDK 1.4. It contains the JDBC driver
classes, except classes for NLS support in Oracle Object and
Collection types.
Then the driver url is wrong. Are you sure you can connect with this form of url: jdbc:oracle:thin:@peanut:1 521:pad ?
ASKER
Yes. This is the same connection URL my Websphere datasource uses and it works perfectly.
Try to register the driver: Class.forName("oracle.jdbc .OracleDri ver"); if you have access to the initialization code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.