Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2005

Tip: Looking for answers? Try searching our database.

getting weblogic db connection confusion

Thread view: 
laredotornado@zipmail.com - 20 Jun 2005 19:43 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.