The key point is to create the ".bindings file", then replace the file "C:\Interstage\J2EE\var\jndi.bindings".
The method to create ".bindings file" of SQL 2005 is to run the following java program:
import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.microsoft.sqlserver.jdbc.*; import java.sql.ResultSet; public class DataSourceJNDIReg { public static void main(String args) throws Exception{ InitialContext ctx = null; try{ Hashtable env = new Hashtable(5); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:E:/Documents/temp/jndi"); ctx = new InitialContext(env); } catch (NamingException ne) { ne.printStackTrace(); } bind(ctx, "jdbc/ssql2000"); } static void bind(Context ctx, String ln)throws NamingException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setDatabaseName("test"); ds.setPassword("asdf123"); ds.setPortNumber(2786); ds.setServerName("192.168.0.80"); ds.setUser("sa"); System.out.println("Doing a bind with the logical name : " + ln); ctx.bind(ln,ds); System.out.println("Successfully bound"); } }
The generated .bindings file is as follows:
#This file is used by the JNDI FSContext. #Mon Apr 17 18:06:43 CST 2006 jdbc/ssql2000/RefAddr/5/Content=192.168.0.80 jdbc/ssql2000/FactoryName=com.microsoft.sqlserver.jdbc.SQLServerDataSourceObjectFactory jdbc/ssql2000/RefAddr/4/Content=test jdbc/ssql2000/RefAddr/2/Content=asdf123 jdbc/ssql2000/RefAddr/0/Content=com.microsoft.sqlserver.jdbc.SQLServerDataSource jdbc/ssql2000/RefAddr/0/Encoding=String jdbc/ssql2000/RefAddr/0/Type=class jdbc/ssql2000/RefAddr/4/Encoding=String jdbc/ssql2000/RefAddr/1/Type=user jdbc/ssql2000/RefAddr/2/Type=password jdbc/ssql2000/RefAddr/2/Encoding=String jdbc/ssql2000/RefAddr/1/Encoding=String jdbc/ssql2000/RefAddr/3/Content=2786 jdbc/ssql2000/ClassName=com.microsoft.sqlserver.jdbc.SQLServerDataSource jdbc/ssql2000/RefAddr/1/Content=sa jdbc/ssql2000/RefAddr/3/Type=portNumber jdbc/ssql2000/RefAddr/5/Encoding=String jdbc/ssql2000/RefAddr/4/Type=databaseName jdbc/ssql2000/RefAddr/5/Type=serverName jdbc/ssql2000/RefAddr/3/Encoding=String
Using this method you can connect to any database with JDBC driver.
Access SQL Server 2005 64 bit edtion from App Server



Related Items
Comments & Questions