aspose file tools
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
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 56177
    
  13

"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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Masako Liao
Greenhorn

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

Joined: Aug 13, 2004
Posts: 1076

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: 1076

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Connection not working (Oracle and Sun one web server)
 
Similar Threads
Juddi DB connection problem
Connection pooling in tomcat
sun one webserver 6.1 -- javax.naming.NamingException: Cannot create resource instanc
DSN name not found error with TOMCAT5.5.7
JBOSS connection pooling