IMPORTANTE...POOL DE CONEXIONES..COMO!?

Jabili
20 de Diciembre del 2002
Como tengo que cambiar mi programa en el servidor web, para que use un Pool de conexiones?
Entre Connection, PooledConnection, ConnectionPoolDataSource, getConnection(), getPooledConnection() ... estoy hecho un lio!!
GRACIAS!

adam
20 de Diciembre del 2002
test

adam
20 de Diciembre del 2002
espero que esto te ayuda. Es un ejemplo muy Facil de como hacerlo

File:
"HelloWorldExample.java"
-------------------------
/* $Id: HelloWorldExample.java,v 1.1 2000/08/17 00:57:52 horwat Exp $
*
*/

import java.io.*;
import java.text.*;
import java.util.*;

import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
* The simplest possible servlet.
*
* @author James Duncan Davidson
*/

public class HelloWorldExample extends HttpServlet {


public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{

// ***********************************************
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");

PrintWriter out = response.getWriter();
// ***********************************************

try
{
// Register the textFileDriver.
//
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
}
catch (ClassNotFoundException e)
{
System.err.println(
"I could not find the Sybase Driver classes. Did you installn" +
"them as directed in the README file?");
e.printStackTrace();
}

try
{

// **** Connects to sybase database server ***
Connection con =
DriverManager.getConnection("jdbc:sybase:Tds:<ip_address>:<port>/myDatabase_name", "username", "password");

Statement stmt2 = con.createStatement();

stmt2.execute("SELECT description FROM accident_fault_codes ");

ResultSet rs = stmt2.getResultSet();

while (rs.next())
{
// int id = rs.getInt("id");
// String udf_class_name = rs.getString("udf_class_name");
String description = rs.getString("description");

// System.out.println("-*-" + udf_class_name + "-*-");
out.println("-|-" + description + "-|-<br>n");
}

stmt2.close();
con.close();
}

catch (SQLException e)
{
System.err.println("Bad Connection n" + e.toString() + "-n" +
e.getErrorCode() + "-" + e.getSQLState());
System.out.println("-----------------------------------");
System.out.println("--- Stack Trace ------------------");
System.out.println("-----------------------------------");
e.printStackTrace();
System.out.println("-----------------------------------");
}

catch (Exception e)
{
System.out.println("Error: " + e.toString() + e.getMessage() );
}
// ***********************************************
/*
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");

PrintWriter out = response.getWriter();
*/
// ***********************************************

out.println("<html>");
out.println("<head>");

String title = rb.getString("helloworld.title");

out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor="white">");
out.println("<body>");

// note that all links are created to be relative. this
// ensures that we can move the web application that this
// servlet belongs to to a different place in the url
// tree and not have any harmful side effects.

// XXX
// making these absolute till we work out the
// addition of a PathInfo issue

out.println("<a href="/examples/servlets/helloworld.html">");
out.println("<img src="/examples/images/code.gif" height=24 " +
"width=24 align=right border=0 alt="view code"></a>");
out.println("<a href="/examples/servlets/index.html">");
out.println("<img src="/examples/images/return.gif" height=24 " +
"width=24 align=right border=0 alt="return"></a>");
out.println("<h1>" + title + "***</h1>");
out.println("</body>");
out.println("</html>");
}
}