Connection pooling concept through weblogic 8.1

Hi,

I tried using connection pooling concept through weblogic 8.1 .

import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
public class ConnectionpoolDemo {
public static void main(String[] args) {
try {
InitialContext ic=new InitialContext();
Object obj=ic.lookup("MyDsJNDI");
DataSource ds=(DataSource)obj;
Connection con=ds.getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select empno,ename from emp");
while(rs.next()){
System.out.print(rs.getString(1)+"t");
System.out.println(rs.getString(2));
}
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}

}

Output:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at ConnectionpoolDemo.main(ConnectionpoolDemo.java:8)



EXCEPTION OCCURRED AT LINE

Object obj=ic.lookup("MyDsJNDI");

Questions by balinaidu007   answers by balinaidu007

Showing Answers 1 - 6 of 6 Answers

cvshankar

  • Apr 23rd, 2008
 

The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes made by others

  Was this answer useful?  Yes

ashwin1483

  • May 15th, 2008
 

try using this code............


import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class ConnectionPool
{
 public static void main(String args[])
 {
  try
  {
   Hashtable hs=new Hashtable();
   hs.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
   hs.put(Context.PROVIDER_URL,"t3://localhost:7001");
   Context ctx=new InitialContext(hs);
   DataSource ds=(DataSource)ctx.lookup("connectionpooling");
   Connection con=ds.getConnection();
   Statement st=con.createStatement();
   ResultSet rs=st.executeQuery("select ename,epwd from emp");
   while(rs.next())
   {
    System.out.println(rs.getString(1)+" "+rs.getString(2) );
   }
  }
  catch (Exception e)
  {
   System.out.println("error" +e);
  }
 }
}
  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions