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 |
Explain what should be done when a SQL exception is raised?
why are using type4 driver in realtime projects?
What are different types of JDBC Drivers?
Explain the life cycle of jdbc.
How a driver can be loaded?
Explain the difference between rowset vs. Resultset in jdbc?
Can we make a database connection from HTML ?
6 Answers Aptech, BOB Technologies, Cap Gemini, Wipro,
How do I connect to jdbc?
In JDBC, All the API?s are interfaces? Where is the actual implementation?
How the JDBC application works?
How do I set properties for a JDBC driver and where are the properties stored?
What is a jdbc url?