De: Conrad Peres [mailto:[EMAIL PROTECTED]
Enviada em: quarta-feira, 7 de julho de 2004 11:55
Para: [EMAIL PROTECTED]
Assunto: [JUG-Petro] ConnectionPool
Senhores,
Estou fazendo meu Primeiro Connection Pool, gostaria de algumas dicas de vcs, atualmente todas as aplica��es est�o fazendo uma conex�o a cada request do cliente, o que deixa a aplica��o lenta.
Como eu fa�o pra usa o Connection Pool do Pr�prio conteiner tomcat ou jboss?
porque estou tentando instanciar um ConnectionPool e esta dando erro de compila��o.
Aguardo resposta
Atenciosamente
Conrad Peres.
package util;
//import java.io.PrintStream;
import
java.sql.*;
import
javax.servlet.http.HttpSessionBindingEvent;
//import
javax.servlet.http.HttpSessionBindingEvent;
//import
javax.servlet.http.HttpSessionBindingListener;
public class ConnectionBean {
private Connection connection;
private Statement
statement;
//private static final String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
//private static final String dbURL =
"jdbc:odbc:TesteDix";
//private static final String driver =
"com.pointbase.jdbc.jdbcUniversalDriver";/**/
private static final
String dbURL = "172.16.1.19:1521:ORCL";/*BANCO
CPD*/
//private static final
String dbURL = "192.168.30.12:1521:unipro";/*BANCO
FORA!!!!!!!!!!!!!!!!!!!!!*/
private static final String login
= "unipro";
private static final
String password = "unipro";
private static
final String user = "unipro";
public
ConnectionBean( ) {
try
{
// Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@" + database, user,
password);
//
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());/**/
//driver="oracle.jdbc.driver.OracleDriver()";
//Class.forName( driver
);/**/
//connection = DriverManager.getConnection( dbURL, login, password
);
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
connection = DriverManager.getConnection ("jdbc:oracle:thin:@" + dbURL,
user,
password);
statement
= connection.createStatement( );
//System.out.println("CB
instanci�");
} catch( SQLException
sqlexception )
{
System.err.println( "ConnectionBean: driver not loaded"
);
//sqlexception.printStackTrace();
connection = null;
}
catch( Exception e)
{
System.err.println( "ConnectionBean: driver unavailable"
);
connection = null;
}
}
public
Connection getConnection( ) {
return connection;
}
public void commit( ) throws
SQLException {
connection.commit(
);
}
public void rollback( ) throws
SQLException {
connection.rollback( );
}
public void setAutoCommit( boolean
flag ) throws SQLException {
connection.setAutoCommit( flag );
}
public boolean getAutoCommit( ) throws
SQLException {
return
connection.getAutoCommit( );
}
public ResultSet executeQuery( String
s ) throws SQLException {
return
statement.executeQuery( s );
}
public int executeUpdate( String s )
throws SQLException {
return
statement.executeUpdate( s );
}
public ResultSet prepareCallQuery(
String s ) throws SQLException {
java.sql.CallableStatement callablestatement = connection.prepareCall( s
);
return
callablestatement.executeQuery( );
}
public int prepareCallUpdate( String s
) throws SQLException {
java.sql.CallableStatement callablestatement = connection.prepareCall( s
);
return
callablestatement.executeUpdate( );
}
public void valueBound(
HttpSessionBindingEvent httpsessionbindingevent )
{
System.err.println(
"ConnectionBean: in the valueBound method"
);
try
{
if(
connection == null || connection.isClosed( ) )
{
connection = DriverManager.getConnection( dbURL,
login, password
);
statement = connection.createStatement(
);
}
} catch( SQLException
sqlexception )
{
connection = null;
}
}
public void valueUnbound( HttpSessionBindingEvent
httpsessionbindingevent ) {
try
{
connection.close( );
} catch(
SQLException sqlexception ) {
} finally
{
connection = null;
}
}
public void finalize( )
{
try
{
statement.close(
);
connection.close( );
//System.out.println("CB
liber�");
} catch( SQLException
sqlexception ) {
} finally
{
connection = null;
}
}
}
Yahoo! Mail agora ainda melhor: 100MB, anti-spam e antiv�rus gr�tis!
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/jug-petropolis/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
