开发者

How to connect data base using jndi datasource in weblogic

How to connect data base using jndi datasource in weblogic. i am using following code but it is giving null value for connection

Context ctx = null;
    Hashtable evn = new Hashtable();
                evn.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    evn.put(Context.PROVIDER_URL,"t3://localhost:7001");    

    Connection conn = null;
    try {
     ctx = new InitialContext(evn);
     javax.sql.DataSource ds 
                      = (javax.sql.DataSource) ctx.lookup ("mydatasource");
          conn = ds.getConnection();
                  }catch (Exception e) {
                      System.out.println();
 开发者_JS百科                   // TODO: handle exception
                                }


Append this to clarify more about exception reason

catch(Exception sqlExp)
{        
   throw new SQLException("getConnection :: Exception"+sqlExp);
}


  1. post the exception as suggested by Stano
  2. on weblogic console test the connection http://docs.oracle.com/cd/E23943_01/web.1111/e13737/jdbc_datasources.htm#CHDIIFHH

  3. did you target the datasource to weblogic server where the application works?


     //try this code:

     Connection con = null;
     DataSource datasource = null;

     Context initialContext = new InitialContext();

     // "jdbc/MyDBname" >> is a JNDI Name of DataSource on weblogic

     datasource = (DataSource) initialContext.lookup("jdbc/MyDBname");

     con = datasource.getConnection();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜