0

I am trying to use a datasource that I set up on my weblogic server. datasource JNDI name = thinOracleDataSource

in my code I have the following

public class DAOBean implements java.io.Serializable {
private Connection conn;
public void connect() throws ClassNotFoundException,
SQLException, NamingException {
Context ctx = new InitialContext();
// Lookup using JNDI name.
DataSource ds = (javax.sql.DataSource) ctx.lookup("thinOracleDataSource");
conn = ds.getConnection();

}

But I get this error

 javax.naming.NameNotFoundException: While trying to look up /thinOracleDataSource in /app/webapp/PreAssignment2/24911485.; remaining name '/thinOracleDataSource'

am I looking the JNDI name in the right way? or am I missing something? Thanks for any help!!

EDIT: This is the jndi tree that I can get from the weblogic console enter image description here

4

2 回答 2

3

尝试jdbc/thisOracleDataSource在 Weblogic 中命名您的数据源并将其引用为:

DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/thinOracleDataSource");

此外,请确保数据源“针对”您的 weblogic Java 服务器。所有这些都可以在 Weblogic 管理控制台中完成。

于 2012-10-26T15:58:13.773 回答
1

您的 JNDI 密钥应该类似于"java:comp/env/jdbc/thinOracleDataSource". 您可以使用允许在 JNDI 中访问(可能还包括搜索)的 Weblogic 控制台来验证它。因此,您可以在编写代码之前手动检查。

于 2012-10-26T15:32:26.470 回答