Client to test Multidatasource Failover/Loadbalancing Feature of WLS
import javax.naming.*;
import java.util.*;
import javax.rmi.*;
import javax.sql.*;
import java.sql.*;
public class MyDsClient
{
public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
private static String serverUrl ="t3://localhost:7001";
public static void main(String ar[])throws Exception
{
PreparedStatement pr = null;
InitialContext ic=null;
try{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, serverUrl);
ic = new InitialContext(env);
}
catch(Exception e){}
try{
Connection con[]=new Connection[1000];
for(int i=0;i<1000;i++)
{
Object obj=ic.lookup("mds");
DataSource ds=(DataSource)obj;
con[i]=ds.getConnection();
System.out.println("\n\nGot the Connection : "+con[i]);
pr = con[i].prepareStatement("insert into test values(?)");
pr.setInt(1,i);
System.out.println(i);
int rs = pr.executeUpdate();
System.out.println("ROWS UPDATED:"+ rs);
try {
Thread.sleep(1000);
} catch(Exception ee)
{
ee.printStackTrace();
}
con[i].close();
}
}
catch(Exception e)
{
System.out.println("\n\n\t jack Exception => "+e);
e.printStackTrace();
}
}
}
0 comments:
Post a Comment