http://www.java-cn.net/technology/technology_detail.jsp?id=465
http://www.java-cn.net/technology/technology_detail.jsp?id=1185
http://www.java-cn.net/technology/technology_detail.jsp?id=1246
http://www.java-cn.net/technology/technologybrow.jsp
去看看吧
http://www.java-cn.net/technology/technology_detail.jsp?id=1185
http://www.java-cn.net/technology/technology_detail.jsp?id=1246
http://www.java-cn.net/technology/technologybrow.jsp
去看看吧
public static Connection getDBConnection()
{
ConnectionPoolDataSource ds = null;
PooledConnection pconn = null;
Connection conn = null;
Context initCtx=null;
Context envCtx=null;
try
{
initCtx = new InitialContext();
}
catch (NamingException ne1)
{
System.err.println( "Error on initalcontext:" + ne1.getMessage() );
}
try
{ envCtx = (Context) initCtx.lookup("java:/comp/env"); }
catch (NamingException ne2)
{
System.err.println( "Error on lookup env:" + ne2.getMessage() );
}
try
{
ds = (ConnectionPoolDataSource)envCtx.lookup("jdbc/dbconnection");
}
catch (NamingException ne3)
{
System.err.println( "Error on lookup jndi:" + ne3.getMessage() );
} int tryCount = 0; try
{
pconn = ds.getPooledConnection();
conn = pconn.getConnection();
}
catch (SQLException se)
{
//if (tryCount == 2)
System.err.println("tttt" + se.getMessage());
}
return conn;
}
public opendb()
{
initCtx.lookup("java:/comp/env"); } public ResultSet executeQuery(String sql)
{
rs = null;
try{
conn1 = getDBConnection();
stmt = conn1.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public static Connection getDBConnection()
{
ConnectionPoolDataSource ds = null;
PooledConnection pconn = null;
Connection conn = null;
Context initCtx=null;
Context envCtx=null;
try
{
initCtx = new InitialContext();
}
catch (NamingException ne1)
{
System.err.println( "Error on initalcontext:" + ne1.getMessage() );
}
try
{ envCtx = (Context) initCtx.lookup("java:/comp/env"); }
catch (NamingException ne2)
{
System.err.println( "Error on lookup env:" + ne2.getMessage() );
}
try
{
ds = (ConnectionPoolDataSource)envCtx.lookup("jdbc/dbconnection");
}
catch (NamingException ne3)
{
System.err.println( "Error on lookup jndi:" + ne3.getMessage() );
} int tryCount = 0; try
{
pconn = ds.getPooledConnection();
conn = pconn.getConnection();
}
catch (SQLException se)
{
System.err.println("tttt" + se.getMessage());
}
return conn;
}
public ResultSet executeQuery(String sql)
{
rs = null;
try{
conn1 = getDBConnection();
stmt = conn1.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}