%@ page import="
java.io.*,
java.sql.*,
javax.servlet.*,
javax.servlet.http.*,
java.util.Properties,
weblogic.db.jdbc.*
"%>
<%
/* ---------------------------------
get parameters from HTTP request
http://server.gottry.com:7001/KenTest.jsp?Sleep=0&JDBC=TestPool
where
Sleep is number of milliseconds to sleep after issuing the
SQL call before releasing the JDBC entry back to the pool
This simulates "processing time" in a real application
JDBC is the name of the JDBCConnectionPool as defined in the
WebLogic config.xml file. This can also be the name of
a WebLogic JDBCMultiPool
Close is a Y/N switch to indicate if the JSP should emulate a
well-behaved application and close the JDBC entry was done
(Close=Y)
-----------------------------------*/
String SleepSeconds = request.getParameter("Sleep");
String JDBC = request.getParameter("JDBC");
String CloseIt = request.getParameter("Close");
if(SleepSeconds == null) { SleepSeconds = "0";}
if(JDBC == null) { JDBC = "JDBCPool";}
if(CloseIt == null) { CloseIt = "Y";}
int SleepInterval = Integer.parseInt(SleepSeconds);
String JDBCPool = "jdbc:weblogic:pool:" + JDBC;
%>
<%
Connection conn = null;
try {
out.println("acquiring JDBC pool entry from ... " + JDBC + "
" );
out.flush();
Driver myDriver = (Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = myDriver.connect(JDBCPool, null);
Statement stmt = null;
ResultSet rs = null;
stmt = conn.createStatement();
rs = stmt.executeQuery("select sysdate from dual");
while (rs.next()) {
java.sql.Date nowdate = rs.getDate("sysdate");
out.println("Sysdate=" +nowdate+"
");
out.flush();
}
if(SleepInterval != 0)
try {
out.println("sleeping for " + SleepSeconds + "milliseconds after SQL call
" );
out.flush();
Thread.sleep(SleepInterval);
out.println("Done
" );
out.flush();
}
catch (Exception e){
out.print("sleep after Failed
" + e.getMessage());
}
}
catch (Exception e){
out.print("
Connection Failed" + e.getMessage());
}
finally {
if (CloseIt == "Y") {
out.println("Closing JDBC connection
" );
out.flush();
if(conn != null)
try{
conn.close();
}
catch (Exception e){
out.print("Exception:" + e);
}
} else {
out.println("*** skipping the close for JDBC connection
" );
out.flush();
}
}
%>