//********************************************************************* // // Copyright (c) 2004-2008 by Teradata Corporation // All Rights Reserved // //********************************************************************* // // File: T21300JD.java // Purpose: Create a Data Source // //********************************************************************* import java.lang.reflect.* ; import javax.naming.*; import javax.sql.*; import java.util.*; public class T21300JD { private static void callSetter (DataSource ds, String sMethodName, String sValue) throws IllegalAccessException , InvocationTargetException , NoSuchMethodException { Method meth = ds.getClass ().getMethod (sMethodName, new Class [] {String.class}) ; meth.invoke (ds, (Object []) new String [] {sValue}) ; } public static void main(String[] args) throws ClassNotFoundException , IllegalAccessException , InvocationTargetException , InstantiationException , NamingException , NoSuchMethodException { System.out.println(" \n Sample T21300JD: \n" ); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.setProperty(Context.PROVIDER_URL, "file:."); Class cls = Class.forName ("com.teradata.jdbc.TeraDataSource") ; DataSource ds = (DataSource) cls.newInstance () ; // required parameters callSetter (ds, "setDSName", "whomooz"); //dataBase server name callSetter (ds, "setUser", "guest"); //user name callSetter (ds, "setPassword", "please"); //password // optional parameters - these setxxx methods can be omitted callSetter (ds, "setDescription", "test data source"); //description callSetter (ds, "setTMODE", "ANSI"); callSetter (ds, "setCHARSET", "UTF8"); Context ctx = new InitialContext(env); System.out.println("Removing previous JNDI name binding, if any"); ctx.unbind("TeraData1"); System.out.println("Binding DataSource object to JNDI name"); ctx.bind("TeraData1", ds); //known to users by this name System.out.println("Successfully bound DataSource object to JNDI name"); System.out.println(" Sample T21300JD finished."); } // end main } // end class T21300JD