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.
and bind the JNDI reference for a FBConnectionPoolDataSource class:<br />
1<br />
2<br />
3<br />
4<br />
package hello;<br />
import javax.naming.*;<br />
import org.firebirdsql.pool.*;<br />
public class HelloBindJndi {<br />
}<br />
public static void main(String[] args) throws Exception {<br />
}<br />
Reference ref = new Reference(<br />
"org.firebirdsql.pool.FBConnectionPoolDataSource");<br />
ref.add(new StringRefAddr("maxPoolSize", "5"));<br />
ref.add(new StringRefAddr("minPoolSize", "2"));<br />
ref.add(new StringRefAddr("maxStatements", "10"));<br />
ref.add(new StringRefAddr("maxIdleTime", "108000"));<br />
ref.add(new StringRefAddr("database",<br />
"localhost/3050:C:/db/employee.fdb));<br />
ref.add(new StringRefAddr("user", "SYSDBA"));<br />
ref.add(new StringRefAddr("password", "masterkey"));<br />
Context ctx = new InitialContext();<br />
ctx.bind("jdbc/test", ref);<br />
Illustration 2.9.: Example of initializing and binding FBConnectionPoolDataSource reference.<br />
1. Create reference instance for the FBConnectionPoolDataSource. According<br />
to the JNDI specification we could specify another type here, however the<br />
identifier specified here is used later by the object factory to check whether it is<br />
responsible for materializing the specified reference. Our object factory accepts<br />
only references with the ID equal to<br />
"org.firebirdsql.pool.FBConnectionPoolDataSource".<br />
2. Fill the pooling properties as reference addresses.<br />
3. Fill the database connection properties. Steps 2 and 3 look quite strange from<br />
the programming point of view, especially compared to the Illustration 2.8.<br />
However, this approach is very elegant if we consider reading the configuration<br />
from the file. In this case we no longer have to use <strong>Java</strong> reflection to set needed<br />
properties – object factory does it for us.<br />
4. Create JNDI initial context and bind the reference to the specified name.<br />
Chapter 2. Obtaining a connection 18