Creating a data source
От | Larry Mulcahy |
---|---|
Тема | Creating a data source |
Дата | |
Msg-id | 3AF9B1EA.B041D6ED@qip.qwest.net обсуждение исходный текст |
Список | pgsql-jdbc |
I'm trying to create a data source as described in paragraph 5.5.1 of the JDBC 2.0 Standard Extension API (http://java.sun.com/products/jdbc/jdbc20.stdext.pdf). (Another example: paragraph 3.7.2 "Deploying a Basic Datasource Object" in http://developer.java.sun.com/developer/Books/JDBCTutorial/). My application produces the output, java -classpath .:/usr/local/pgsql/share/java/postgresql.jar:/usr/local/java/jdbc2_0-stdext.jar Example Creating a new Context... Binding... Bind failed. Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial I found various documentation about different ways to specify a value for java.naming.factory.initial. You can put it in $JAVA_HOME/lib/jndi.properties, you can specify it on the command line with -Djava.naming.factory.initial=..., you can create an environment Hashtable and pass it as one of the arguments to InitialContext as documented at http://java.sun.com/products/jndi/tutorial/beyond/env/. What I can't find is what value to actually give it for the InitialContextFactory. Am I supposed to write this myself? This seems like a routine common action that people must do all the time, but I can't seem to find good documentation about how to do it. Is there some administration that needs to be done behind the scenes, e.g. starting a JNDI server? Code follows: import javax.naming.InitialContext; import javax.naming.Context; import java.util.Hashtable; public class Example { public static void main(String args[]) { org.postgresql.PostgresqlDataSource ds = new org.postgresql.PostgresqlDataSource(); ds.setServerName("host"); ds.setDatabaseName("database"); Context ctx = null; System.out.println("Creating a new Context..."); try { ctx = new InitialContext(); } catch (Exception e) { System.out.println("Failed to create a new Context."); System.out.println("Exception: " + e); return; } System.out.println("Binding..."); try { ctx.bind("jdbc/database", ds); } catch (Exception e) { System.out.println("Bind failed."); System.out.println("Exception: " + e); return; } } } -- Larry Mulcahy lmulcahy@qip.qwest.net PGP public key at: http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=0x2C4C5A03
В списке pgsql-jdbc по дате отправления: