码迷,mamicode.com
首页 > 其他好文 > 详细

给出一个JNDI用来查找dataSource的例子?

时间:2018-09-26 18:18:25      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:base   optional   util   sda   mysq   bec   ack   cat   int   

8.JNDI用来查找dataSource的例子:(视频下载) (全部书籍)

import javax.naming.InitialContext;
import javax.naming.Context;

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;

import java.util.Properties;
import net.sourceforge.jtds.jdbcx.*;
public class ClassPut {
        public static void main(String a[]) {
                try {
/*                  JtdsDataSource dataSource=new  JtdsDataSource();
                        dataSource.setServerName("localhost");
                        dataSource.setDatabaseName("NorthWind");
                        dataSource.setUser("sa");
                        dataSource.setPassword("1234");
*/
                    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
                    ds.setURL("jdbc:mysql://localhost:3306/test");
                    ds.setUser("root");
                    ds.setPassword("1234");                     
                       
                       
                        Properties prop = new Properties();
                        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                                        "com.sun.jndi.fscontext.RefFSContextFactory");

                        Context ctx=new InitialContext(prop);
/*here the following statement writes a file .bindings under the f Disk. because this project is under the f disk.*/
                        ctx.rebind("abc",ds);


                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}
上面的程序只是存入硬盘,想查找出来得用下面的程序:

import javax.naming.InitialContext;
import javax.naming.Context;

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;

详情请见:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner10_web.html#jndiFinddataSource

给出一个JNDI用来查找dataSource的例子?

标签:base   optional   util   sda   mysq   bec   ack   cat   int   

原文地址:https://www.cnblogs.com/mark-to-win/p/9708545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!