| java.lang.Object dinamica.Jndi
Jndi | public class Jndi (Code) | | Provides easy API to obtain a datasource via JNDI
Creation date: 10/09/2003
Last Update: 10/09/2003
(c) 2003 Martin Cordova
This code is released under the LGPL license
author: Martin Cordova (dinamica@martincordova.com) |
Method Summary | |
public static DataSource | getDataSource(String name) Obtain a DataSource object using its JNDI name
Parameters: name - Name of the DataSource like "jdbc/demo" or "java:comp/env/jdbc/demo"depending on your Server/JNDI provider
Sample code:
javax.sql.DataSource ds = Jndi.getDataSource("java:comp/env/jdbc/demo");java.sql.Connection conn = ds.getConnection(); Please keep in mind that some servers only accept "jdbc/demo" excludingthe prefix "java:comp/env/", and may throw errors if you try to use the prefix,so it is a good idea to keep this String in a configuration file, like a contextparameter in WEB.XML and load it at runtime, to make your WebApp more flexible and portable. |
getDataSource | public static DataSource getDataSource(String name) throws Throwable(Code) | | Obtain a DataSource object using its JNDI name
Parameters: name - Name of the DataSource like "jdbc/demo" or "java:comp/env/jdbc/demo"depending on your Server/JNDI provider
Sample code:
javax.sql.DataSource ds = Jndi.getDataSource("java:comp/env/jdbc/demo");java.sql.Connection conn = ds.getConnection(); Please keep in mind that some servers only accept "jdbc/demo" excludingthe prefix "java:comp/env/", and may throw errors if you try to use the prefix,so it is a good idea to keep this String in a configuration file, like a contextparameter in WEB.XML and load it at runtime, to make your WebApp more flexible and portable. DataSource to provide access to a connection pool throws: Throwable - |
|
|