my dog learned polymorphism*
The moose likes JDBC and the fly likes Connection not working (Oracle and Sun one web server) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection not working (Oracle and Sun one web server)" Watch "Connection not working (Oracle and Sun one web server)" New topic
Author

Connection not working (Oracle and Sun one web server)

Masako Liao
Greenhorn

Joined: Sep 30, 2004
Posts: 2
need help~
connection not working.
ERROR is:Cannot create resource instance

DB racle 8.1
Server:Sun one web server 6.1
JDBC Connection Pool : moea_db
JDBC Resource : moeaDataSource

below is my code:

try {
InitialContext initContext = new InitialContext();
DataSource source = (DataSource) initContext.lookup("java:comp/env/jdbc/moeaDataSource");
Connection conn = source.getConnection();

} catch( Exception e) {
out.println("<br><font color=red>ERROR:</font>"+e.getMessage());
}


Web.xml
---------------------------------------------------------------------
<resource-ref>
<description>moea database</description>
<res-ref-name>jdbc/moeaDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
---------------------------------------------------------------------

Why i can't create resource instance ???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60749
    
  65

"need help",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Masako Liao
Greenhorn

Joined: Sep 30, 2004
Posts: 2
OK! sorry~~ i change it.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

hi first narrow your problem. In your code there are two place where problem may come

1. when you are looking up your DataSource
2. WHen you are creating connection

first keep them in differnt try-catch block and then see..even your problem seems to related with looking of data source.


try {
InitialContext initContext = new InitialContext();
DataSource source = (DataSource) initContext.lookup("java:comp/env/jdbc/moeaDataSource");
Connection conn = source.getConnection();

} catch( Exception e) {
out.println("<br><font color=red>ERROR:</font>"+e.getMessage());
}


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Sorry forgot to paste changed code

Connection conn = null;
DataSource source = null;
InitialContext initContext = null;

try {
InitialContext initContext = new InitialContext();
source = (DataSource) initContext.lookup("java:comp/env/jdbc/moeaDataSource");
}
catch( Exception ex1) {
System.out.println("Exception is " + ex);
}

try {

Connection conn = source.getConnection();

} catch( Exception ex2) {
out.println("<br><font color=red>ERROR:</font>"+ex2.getMessage());
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection not working (Oracle and Sun one web server)
 
Similar Threads
DSN name not found error with TOMCAT5.5.7
Juddi DB connection problem
sun one webserver 6.1 -- javax.naming.NamingException: Cannot create resource instanc
JBOSS connection pooling
Connection pooling in tomcat