Hi, I am noticing some very bizarre behavior in my attempt to get a
database connection from WebLogic. I'm using an older version, 5.1 sp
12, but I'm hopin gyou can help. If I build a JSP page, like so,
everything works great ...
<%@ page import="java.sql.*" %>
<%
Class.forName("weblogic.jdbc20.pool.Driver").newInstance();
Connection conn =
DriverManager.getConnection("jdbc20:weblogic:pool:myPoolName", null);
%>
This compiles and runs fine. But when I put this same code within a
.javaq file,
public class Test
{
public static Connection getConnection(String poolName) {
try {
Class.forName("weblogic.jdbc20.pool.Driver").newInstance();
Connection conn =
DriverManager.getConnection("jdbc20:weblogic:pool:" + poolName, null);
return conn;
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Class not found: "
+ cnfe.getMessage());
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage());
}
}
} // Test
and then build a JSP consisting of
<%@ page import="java.sql.*" %>
<%@ page import="com.hrw.support.db.*" %>
<%
Connection c = Test.getConnection("myPoolName");
%>
a ClassNotFoundException is thrown from within the getConnection method
of the Test class. Any ideas on what could be going on?
Thanks, - Dave
joeNOSPAM@BEA.com - 20 Jun 2005 20:38 GMT
Hi. I'll guess that whatever program is compiling the javaq
file doesn't have all the weblogic classes in it's classpath.
Here is a much cleaner version of your getConnection()
method, which will compile anywhere. It will still have to
*run* with WebLogic classes...
public static Connection getConnection(String poolName) {
try {
java.sql.Driver d = (java.sql.Driver)
Class.forName("weblogic.jdbc20-.pool.Driver").newInstance();
return d.connect("jdbc20:weblogic:pool:" + poolName, null);
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Class not found: "
+ cnfe.getMessage());
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage-());
}
}
Joe Weinstein at BEA