You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rick Fincher <rn...@tbird.com> on 2003/05/29 01:37:15 UTC

Jaybird with Tomcat, Part II

Hi Robert,

I use JayBird with Tomcat on a Win 2000 system all the time with no
problems, and Linux, and Sun Solaris.  My setups are below.  There is also a
Jaybird mail group on yahoogroups.com called firebird-java.  You may want to
sign up for that for JayBird specific questions.

E-mail me directly if you have any more specific questions. Oh, upgrading to
4.1.24 is a good idea too, for the bug fixes and because you can use data
sources in realms (allowing you to pool login connections).

Rick Fincher
rnf@tbird.com

Partial WEB-INF/web.xml for Firebird data source:
<resource-ref>

<description>DB Connection</description>

<res-ref-name>jdbc/db</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>



----------------------------------------------------------------------------
----

Partial conf/server.xml for forebird data source, this uses DBCP to set up a
connection pool.  See the Tomcat docs for setup info, jars needed, etc.

<!-- The following line reads the web app from the unpacked war, it docBase
could be "myWebApp" if you want to use a directory from the unpacked war
file. -->

<Context path="/myWebApp" docBase="myWebApp.war"

debug="0" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"

prefix="localhost_db_log." suffix=".txt"

timestamp="true"/>

<Resource name="jdbc/db"

auth="Container"

type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/db">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<parameter>

<name>removeAbandoned</name>

<value>true</value>

</parameter>

<parameter>

<name>removeAbandonedTimeout</name>

<value>300</value>

</parameter>

<parameter>

<name>logAbandoned</name>

<value>true</value>

</parameter>

<!-- Maximum number of dB connections in pool. Make sure you

configure your Firebird max_connections large enough to handle

all of your db connections. Set to 0 for no limit.

-->

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<!-- Maximum number of idle dB connections to retain in pool.

Set to 0 for no limit.

-->

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<!-- Maximum time to wait for a dB connection to become available

in ms, in this example 10 seconds. An Exception is thrown if

this timeout is exceeded. Set to -1 to wait indefinitely.

-->

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

<!-- Firebird dB username and password for dB connections -->

<parameter>

<name>username</name>

<value>SYSDBA</value>

</parameter>

<parameter>

<name>password</name>

<value>MASTEREY</value>

</parameter>

<!-- Class name for JayBird JDBC driver -->

<parameter>

<name>driverClassName</name>

<value>org.firebirdsql.jdbc.FBDriver</value>

</parameter>

<parameter>

<name>url</name>

<!-- The following could have myhost.mydomain.com instead of localhost. -->

<value>jdbc:firebirdsql:localhost/3050:c:\\databases\\yourdb.gdb</value>

</parameter>

</ResourceParams>

</Context>

------------------------------------

JSP code:

<%@page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*, javax.naming.*,javax.sql.*" errorPage="error.jsp" %>

<!-- Your HTML stuff here, maybe to get input from the user for something to
insert in the DB.

The HTML could go at the end if you want to read stuff from the DB and
display it on the page.

-->

<% // this is the Java code to access the db, it is better to put this in a
bean or servlet but will work inline

try

{

Context ctx = new InitialContext();

if(ctx == null )

throw new Exception("Boom - No Context");

ds = (DataSource)ctx.lookup("java:comp/env/jdbc/db");

}

catch (Exception e)

{

System.out.println("Could Not get data source, error: "+e+"\n");

// put your JSP's error handling stuff here.

}

Connection c;


try

{

c = ds.getConnection();


}

catch (SQLException e)

{

System.out.println("getting new data source connection failed! Error:
"+e+"\n");


// put JSP's error stuff here.

}

String SQLstr = "";  // Your SQL expression appropriate for a prepared
statement goes between quotes.

c.setAutoCommit(false);

PreparedStatement myStatement = c.prepareStatement(SQLstr);

try

{

myStatement .execute();

c.commit();

myStatement .close();

c.close();

}

catch (SQLException e)

{

%>

<jsp:forward page="sqlError.jsp" />

<%

}


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org