Monday 2 May 2011

Configuring datasourse in Glassfish web server

Here we can creating connection for Microsoft SQL Server

Go to JDBC > Connection Pools  click new  add details





you can use any name for pool.click next.Then click finish.Go back to connection pool m,ain menu.click on poolname now created.





.

click additional properties  .click add property like follows






     Now we need to map connection pool to jdbc.

      find  Resources/JDBC/JDBC resources .The click new

specify a JNDI name ,we can use any name for JNDI   but standard is jdbc/name, this we are using in our application to get data source   select the appropriate pool,  in our case jdbc/DsReport .then click finish as follows :





  It can be accessed in java application like this :
            String poolname = "jdbc/DsReport";
            Context ctx = new InitialContext();
            DataSource ds = (DataSource) ctx.lookup(poolname) ;
            Connection con=ds.getConnection();

Note : -Don't forget to properly close the connections














No comments:

Post a Comment