Subject RE: [Firebird-Java] Using FBWrappingDataSource
Author Rick Debay
Find a GOOD book on Java programming and patterns. Putting database
access in your JSP puts you well on the way to being stuck with an
unmaintainable application, as you're mixing your presentation and data
layers. If the database changes, you need to chase down all the queries
you've embedded in your JSPs.
Create a DAO (see any Java patterns book, such as Core J2EE Patterns by
Alur et al), and have it manage connections transparently for you. Have
the servlet call into the DAO and then place the data in the request
context, and have the JSP then get the data out of the request context
for display.

-----Original Message-----
[] On Behalf Of sugi
Sent: Saturday, April 30, 2005 11:29 AM
Subject: [Firebird-Java] Using FBWrappingDataSource


Coming from Delphi background, I'm a newbie to Jaybird so please excuse
me if the following questions are RTFM-ish.

Creation Strategy
As far as I understand it, Tomcat's preferred method to configure JDBC
Data Sources is through JNDI. But the steps required to manage this is a
bit painful. If not because of a very helpful post by rfincher2000 to
this mailing list a while ago, i could never get it to work. Here's the
steps involved;

1. Copy the jaybird jar files to Tomcat's common\lib directory.
2. Create a context configuration file (context.xml) file in the WEB-INF
folder, declaring how to access the database (including username and
<Resource name="jdbc/dbTest" auth="Container"
maxWait="-1" />
3. Add the following items to the application's web.xml.
<description>Test SQL DB Connection</description>
4. Retrieve the DataSource from the application, which involves several
Context lookup calls.

As an aside, I cannot get step #2 above to work in my development
environment (Eclipse + sysdeo tomcat plugin) so I resorted to hacking
the actual my_app.xml file in tomcat\conf\catalina\localhost\ directory.

Anyway, I came across a different approach that I prefer because it
spares me all the JNDI configuration headache. It involves using one
servlet as the main controller/dispatcher (i.e. Front Controller). Then
we create an instance of FBWrappingDataSource and add it to the servlet
context (a.k.a. "application" inside JSPs).

FBWrappingDataSource ds = new FBWrappingDataSource();
ServletContext sc = this.getServletContext();
sc.setAttribute("datasource", ds);

Inside JSPs, here's the code to get the DataSource instance:
DataSource ds = (DataSource) application.getAttribute("datasource");
Connection c = ds.getConnection();

So, since the second approach is obviously shorter and easier, is there
any drawbacks/gotchas of using this approach that i should be aware of?
What is the advantage of using the convoluted JNDI approach which is
probably not portable across containers?

PreparedStatement vs Statement
After instantiating a FBWrappingDataSource and getting a connection from
it, Using a plain "Statement" instead of "PreparedStatement" always
result in "-901 feature not supported" errors. Is this 'normal', or am i
missing something obvious?

Thanks in advance,

Yahoo! Groups Links