Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird
Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird
Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
package hello;<br />
import java.sql.*;<br />
import javax.sql.*;<br />
import org.firebirdsql.pool.*;<br />
public class HelloConnectionPool {<br />
}<br />
public static void main(String[] args) throws Exception {<br />
}<br />
org.firebirdsql.pool.FBWrappingDataSource pool =<br />
new org.firebirdsql.pool.FBWrappingDataSource();<br />
pool.setMaxPoolSize(5);<br />
pool.setMinPoolSize(2);<br />
pool.setMaxStatements(10);<br />
pool.setMaxIdleTime(30 * 60 * 60);<br />
pool.setDatabase("localhost/3050:C:/db/employee.gdb");<br />
pool.setUser("SYSDBA");<br />
pool.setPassword("masterkey");<br />
// no step 4 as in previous example<br />
// obtain a wrapped connection<br />
Connection connection = pool.getConnection();<br />
try {<br />
// do something here...<br />
} finally {<br />
}<br />
// release the connection back to pool<br />
connection.close();<br />
Illustration <strong>2.1</strong>1.: Example of instantiating and using the javax.sql.DataSource implementation<br />
This class is called “wrapping” because it wraps the connection pool and<br />
delegates all calls to the underlying implementation. As you can see, the code is<br />
very similar to the Illustration 2.8, only few places are different. Please note, that<br />
there is no longer Step 4, the wrapper does this automatically in<br />
getConnection() method used in Step 5.<br />
The javax.sql.XADataSource implementation<br />
<strong>JDBC</strong> 2.0 specification introduced the javax.sql.XADataSource interface that<br />
should be used to access connections that can participate in distributed<br />
transactions with JTA-compatible transaction coordinator. This gives applications<br />
possibility to use two-phase commit to synchronize multiple resource managers.<br />
<strong>Jaybird</strong> <strong>2.1</strong> does not have separate class, but FBConnectionPoolDataSource also<br />
implements the javax.sql.XADataSource interface. For information how to<br />
instantiate this class please see Illustration 2.8.<br />
Applications usually do not need to access the javax.sql.XADataSource directly,<br />
this is task for a J2EE container. Chapter XXX contains more detailed description<br />
of distributed transactions and contains code to access and manipulate connections<br />
that participate in distributed transactions.<br />
Chapter 2. Obtaining a connection 20