users@glassfish.java.net

how to use glassfish connection pool in Stand alone application

From: <glassfish_at_javadesktop.org>
Date: Wed, 25 Jun 2008 05:16:31 PDT

can any body help me , i search API what i know ..can any body give hint where i did mistake ...my problem is


from glasshFish console i created JDBC Conntion pool and JDBC resources by using the following commands

1-----> >[b]asadmin create-jdbc-connection-pool --user admin --host localhost --port 4848 --datasourceclassname org.apache.derby.jdbc.ClientDataSource --restype javax.sql.XADataSource --property portNumber=3306:password=admin:user=root:serverName=localhost:databaseName=validate:connectionAttributes=\\;create\\\\=true myconnectionpool[/b]


2----> [b]asadmin create-jdbc-resource --user admin --connectionpoolid myconnectionpool jdbc/mycpool
[/b]
now my problme is how to use connetion from this connection pool in [b]my Stand alone application[/b]

i written code for this as follow ,but not aable to get coonetion.

public static void main(String a[]){

InitialContext ic = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ic .lookup("jdbc/mycpool");
Connection con = ds.getConnection();

}




[b]i am getting following exception[/b]

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.list(Unknown Source)
        at com.alw.connectionPool.MyConnecctionPoolDemo.main(MyConnecctionPoolDemo.java:23)
[Message sent by forum member 'gbabu' (gbabu)]

http://forums.java.net/jive/thread.jspa?messageID=282477