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 |
what is call level interface?
Can resultset be null in java?
How to retrieve warnings in jdbc?
What is jndi lookup?
How do I find whether a parameter exists in the request object?
What is the use of JDBC DriverManager class?
What are collection pools?
How to move the cursor in scrollable resultset ?
What is DML?
What is Normalization?
2 Answers Accenture, Atos Origin,
How do I check in my code whether a maximum limit of database connections have been reached?
How many rowset are available in jdbc?