Java/Database SQL JDBC/JDBC JDNI — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 09:34, 1 июня 2010
JNDI and JDBC
<source lang="java">
/* Java Programming with Oracle JDBC by Donald Bales ISBN: 059600088X Publisher: O"Reilly
- /
import java.sql.*; import java.util.*; import javax.naming.*; import oracle.jdbc.pool.*; public class TestDSBind {
public static void main(String args[]) throws SQLException, NamingException { // For this to work you will need to create the // directories /JNDI/JDBC on your file system first Context ctx = null; try { Properties prop = new Properties(); prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC"); ctx = new InitialContext(prop); } catch (NamingException ne) { System.err.println(ne.getMessage()); } OracleDataSource ds = new OracleDataSource(); ds.setDriverType("thin"); ds.setServerName("dssw2k01"); ds.setPortNumber(1521); ds.setDatabaseName("orcl"); ds.setUser("scott"); ds.setPassword("tiger"); ctx.bind("joe", ds); }
}
</source>