import com.inet.tds.PDataSource; //MERLIA JDBC驱动器中实现DataSource接口的类
import javax.naming.Context; // 实现上下文接口的实例
import javax.naming.InitialContext; // 建立上下文接口的实例
import javax.naming.NamingException; // 抛出异常类型
public class J_JNDI
{ public static void main(String args[]) throws NamingException
{
try{
//建立MERLID JDBC 驱动器中的数据源对象,并设置其属性
PDataSource dataSource=new PDataSource(); //实例化
dataSource.setServerName("127.0.0.1"); //设置数据库服务器所在计算机的IP地址
dataSource.setDatabaseName("tempdb"); // 指定要访问的数据库名称
dataSource.setUser("sa"); // 指定数据库服务器帐号
dataSource.setPassword("thisispassword"); // 指定数据库服务器访问密码
//建立命名服务上下文
Context ctx=new InitialContext();
//设定JNDI服务提供者为”com.sun.jndi.fscontext.RefFSContextFactory"
ctx.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
ctx.addToEnvironment(Context.PROVIDER_URL,"file:D:/naming");
//设定文件系统命名服务的根目录为D:/naming
//通过上下文绑定数据源
String nameOfDataSource="MyDataSource";
ctx.rebind(nameOfDataSource,dataSource);
//判断绑定是否成功
System.out.println(ctx.lookup(nameOfDataSource)+"is bound with"+nameOfDataSource);
ctx.close();
}
catch(NamingException e)
{ System.out.println(e);}
} //End of method main
} //End of class JNDI运行出现下列异常
javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
就这么个简单的应用哪位高手帮忙解决
import javax.naming.Context; // 实现上下文接口的实例
import javax.naming.InitialContext; // 建立上下文接口的实例
import javax.naming.NamingException; // 抛出异常类型
public class J_JNDI
{ public static void main(String args[]) throws NamingException
{
try{
//建立MERLID JDBC 驱动器中的数据源对象,并设置其属性
PDataSource dataSource=new PDataSource(); //实例化
dataSource.setServerName("127.0.0.1"); //设置数据库服务器所在计算机的IP地址
dataSource.setDatabaseName("tempdb"); // 指定要访问的数据库名称
dataSource.setUser("sa"); // 指定数据库服务器帐号
dataSource.setPassword("thisispassword"); // 指定数据库服务器访问密码
//建立命名服务上下文
Context ctx=new InitialContext();
//设定JNDI服务提供者为”com.sun.jndi.fscontext.RefFSContextFactory"
ctx.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
ctx.addToEnvironment(Context.PROVIDER_URL,"file:D:/naming");
//设定文件系统命名服务的根目录为D:/naming
//通过上下文绑定数据源
String nameOfDataSource="MyDataSource";
ctx.rebind(nameOfDataSource,dataSource);
//判断绑定是否成功
System.out.println(ctx.lookup(nameOfDataSource)+"is bound with"+nameOfDataSource);
ctx.close();
}
catch(NamingException e)
{ System.out.println(e);}
} //End of method main
} //End of class JNDI运行出现下列异常
javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
就这么个简单的应用哪位高手帮忙解决
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货