public Connection getDbConnection()
    {
        Connection conn = null;
        // 获得连接
        DataSource ds = null;
        try
        {
            Context ctx = new InitialContext();
            ds = (DataSource) ctx.lookup("java:comp/env/PCMSDB");
           //ds = (DataSource) ctx.lookup("PCMSJN");// weblogic环境配置数据源
            Class c = ds.getClass();
            //Object invokeTest = c.newInstance();
            Method getPassword = c.getMethod("getPassword", null);
            Method getUsername = c.getMethod("getUsername", null);
            
            Object pwd = getPassword.invoke(ds, null);
            Object username = getUsername.invoke(ds, null);
            //测试输出
            System.out.println("getDbConnection pwd:"+pwd.toString());
            System.out.println("getDbConnection username:"+username.toString());
        }
        catch (Exception e)
        {
            System.out.println("getDbConnection Exception "+e.getMessage());
            e.printStackTrace();
        }
        try
        {
            conn = ds.getConnection();
        }
        catch (SQLException e)        
        {            
            System.out.println("getDbConnection SQLException "+e.getMessage());
        }
        return conn;

    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
猜你喜欢
  • 2022-12-23
  • 2021-09-16
  • 2021-08-07
  • 2021-08-15
  • 2021-10-31
  • 2021-08-06
相关资源
相似解决方案