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 the difference between client and server database cursors?
How is database middleware used to access legacy databases?
What is the return type of class.forname() method?
What is connection pooling? What Method and class used for Connection pooling in Java?
Why do we need jdbc api?
What does Class.forName return?
What is executequery in java?
Explain the importance of drivermanager.
What is DML?
What does executequery return in java?
How to set NULL values in JDBC PreparedStatement?
What do you understand by jdbc statements?