how do we get the connection from connection pool



how do we get the connection from connection pool..

Answer / paletipatisrinu

import java.io.*;
import java.sql.*;
inport javax.sql.*;
import javax,servlet.http.*;
public class connection extends HttpServlet
{
public void service(HttpServletRequest
req,HttpServletResponse res)throws ServletException,IOException
{
Connection con=makeConnectionPool();
Statement st =con.createStatement();

----------reqular code as like as jdbc--------









}
public void Connection makeConnectionPool()
{
Connection con=null;
try
{
InitialContext ic =new InitialContext();
DataSource ds =(DataSource)ic.lookUp(" jndi logical Name in
Application server");
con=ds.getcConnection();
}catch(Exception e)
{
e.printStackTrace();
}
return con;
}



Note:-First u create logical name of jndi in application
server and refer this api javax.sql.*

Is This Answer Correct ?    7 Yes 0 No

Post New Answer

More JDBC Interview Questions

What class.forname does, while loading the drivers?

0 Answers  


Explain about Join?

0 Answers  


What is an odbc driver?

0 Answers  


What is transaction processing in jdbc?

0 Answers  


How does a file store compare with a jdbc store?

0 Answers  






How is jndi useful for Database connection?

1 Answers  


What is jdbc and jdbc drivers?

0 Answers  


How can I retrieve a String or other object type without creating a new object each time?

0 Answers  


What is the syntax of URL to get connection?

1 Answers  


How do java applications access the database using jdbc?

0 Answers  


What is the jdbc rowset?

0 Answers  


Is java a database?

0 Answers  


Categories