Article View: borland.public.jbuilder.database
Article #412Help with JNDI Datasource in JBuilder 2006
From: Tom Butler
Date: Mon, 28 Nov 2005 00:24
Date: Mon, 28 Nov 2005 00:24
95 lines
4786 bytes
4786 bytes
Need help getting JNDI MySQL database source setup correctly within JBuilder
2006 to support a JSF application. I am able to access the database using
a non-JNDI based approach, and, I was also able to get JNDI to work outside
of JBuilder 2006 using the configuration described below.
I am using the following tomcat documentation as a guide:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html
I have looked through a number of posts and examples, but at this point
(after many non-frutile hours) need someone with experience to help me to
get the configuration correct.
1. Install JDBC Driver
* have 'mysql-connector-java-3.1.11-bin.jar' installed to
/myapp/webmodule/WEB-INF/lib
* also have JDBC driver installed to
/JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/common/lib (this was done as a
troubleshooting step though; prefer to only install this within the project
directory)
2. Declare your Resource Requirements
* following code included in web.xml within project:
/myapp/webmodule/WEB-INF/web.xml
<resource-ref>
<description>MySQL DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. Code your Application's Use of this Resource
* project code from source.java file (note: try/catch blocks not
included)
DataSource pool = null;
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "select * from categories";
ctx = new InitialContext();
pool = (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
conn = pool.getConnection();
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery(); (NOTE! this is statement that causes
the error)
4. Configure Tomcat's Resource Factory
* context.xml contents located at:
/JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/conf/context.xml
<Context debug="5" reloadable="true" crossContext="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/mysql" auth="Container"
type="javax.sql.DataSource"
maxActive="10" maxIdle="30" maxWait="10000"
username="root" password="pat"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test" />
</Context>
note: I also tried to add this same data to a context.xml file located
at /myapp/webmodule/META-INF/context.xml; however, I could not get this
configuration to work, so I placed the context.xml back under the
jakarta-tomcat-5.5.9/conf folder.
ERRORS RECEIVED:
Receive an exception when try to execute the 'rs.=stmt.executeQuery()'
statement. Following is initial start of stack trace:
Nov 27, 2005 7:10:29 PM com.sun.faces.lifecycle.InvokeApplicationPhase
execute
SEVERE: #{bn_searchproviders.search}: javax.faces.el.EvaluationException:
java.sql.SQLException
javax.faces.FacesException: #{bn_searchproviders.search}:
javax.faces.el.EvaluationException: java.sql.SQLException
at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImp
l.java:78)
ALSO TRIED:
* Used Enterprise | Enterprise Setup to add mysql.config to point to mysql
jdbc driver (not sure if I needed this, but tried it as a troubleshooting
step.)
* If I do not attempt to do a JNDI lookup, and just load the database driver
directly (using Class.forName("com.mysql.jdbc.Driver")), everything works
fine (but I don't have the DBCP pooling capability.)
* Was able to get a similar configuration setup to work outside of the
JBuilder 2006 IDE environment
ANY SUGGESTIONS?
* Do I need anything specified in the server.xml file?
THANKS FOR ANY HELP!
Technical Details
Message-ID:
<438a4e03$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1073da,634e789a0dc75d45,start X-Google-Attributes: gid1073da,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Tom Butler" <tom.butler@adelphia.net> Newsgroups: borland.public.jbuilder.database Subject: Help with JNDI Datasource in JBuilder 2006 Date: Sun, 27 Nov 2005 19:24:26 -0500 Lines: 103 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 NNTP-Posting-Host: 68.235.63.81 Message-ID: <438a4e03$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1133137411 68.235.63.81 (27 Nov 2005 16:23:31 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail