乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      OracleJNDI

       小傅哥 2021-12-13
      import java.sql.SQLException;
       
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
       
      import oracle.jdbc.pool.OracleDataSource;
       
      public class OracleJNDI
      {
        
        public OracleJNDI() throws SQLException
        {
        super();
        }
        /**
        * 使用sun提供的com.sun.jndi.fscontext.RefFSContextFactory作為JNDI服務(wù)器,
        * 其實(shí)這是使用文件系統(tǒng)來存儲(chǔ)JNDI對(duì)象
        * @param args
        * @throws NamingException
        * @throws SQLException
        */
        public static void main(String[] args) throws NamingException, SQLException
        {
        
        //Properties ps = new Properties();
        //為系統(tǒng)設(shè)置jndi工廠
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
        "com.sun.jndi.fscontext.RefFSContextFactory");
        //指定JNDI URL
        System.setProperty(Context.PROVIDER_URL, "file:JNDI_REF");
        Context ctx = new InitialContext();
        
        //OracleDataSoruce對(duì)象,它已經(jīng)實(shí)現(xiàn)了javax.naming.Referencable
        OracleDataSource ojndi = new OracleDataSource();
        
        //設(shè)置相關(guān)數(shù)據(jù)庫屬性
        ojndi.setDatabaseName("DXS");
        ojndi.setURL("jdbc:oracle:thin:@localhost:1521:dflcrm");
        ojndi.setUser("smp_dba");
        ojndi.setPassword("123");
        ojndi.setDescription("JDBC Datasource connection.");
        
        //重新綁定OJNDI對(duì)象
        ctx.rebind("ojndi", ojndi);
        System.out.println("bind successful");
        //關(guān)閉
        ctx.close();
        }
       
      }
       
      測試
      import java.sql.Connection;
      import java.util.Properties;
       
      import javax.naming.Context;
      import javax.naming.InitialContext;
       
      import oracle.jdbc.pool.OracleDataSource;
       
      public class Lookup
      {
        /**
        * 這是一個(gè)演示了如果查找JNDI的方法,注意以下二點(diǎn):
        * 1.確保系統(tǒng)屬性中存在Context.INITIAL_CONTEXT_FACTORY和Context.PROVIDER_URL(這不是必須的,如果沒有則2)
        * 2.如果沒有設(shè)置系統(tǒng)屬性,那么必須由相關(guān)的有這二個(gè)變量的HashTable構(gòu)造Context對(duì)象 下面的演示采用第二種實(shí)現(xiàn)
        *  
        * @param args
        * @throws Exception
        */
        public static void main(String[] args) throws Exception
        {
        //構(gòu)造HashTable對(duì)象
        Properties ps = new Properties();
        ps.setProperty(Context.INITIAL_CONTEXT_FACTORY,
        "com.sun.jndi.fscontext.RefFSContextFactory");
        ps.setProperty(Context.PROVIDER_URL, "file:JNDI_REF");
        //由HashTable對(duì)象構(gòu)造Context對(duì)象
        Context ctx = new InitialContext(ps);
        //查找"OJNDI"
        OracleDataSource dataSource = (OracleDataSource) ctx.lookup("ojndi");
        System.out.println("dataSource: " + dataSource);
        Connection conn = dataSource.getConnection();
        System.out.println(conn);
        }
       
      }
      

        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多