• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection not working (Oracle and Sun one web server)

 
Masako Liao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Masako Liao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK! sorry~~ i change it.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic