Also, check your URL. The syntax is also UserName (case-insensitive) Here's my working resource:
<ResourceParams name="jdbc/DataStorage"> <parameter> <name>url</name> <value>jdbc:microsoft:sqlserver://localhost:1433</value> </parameter> <parameter> <name>validationQuery</name> <value>select * from organizations</value> </parameter> <parameter> <name>maxIdle</name> <value>2</value> </parameter> <parameter> <name>maxActive</name> <value>10</value> </parameter> <parameter> <name>driverClassName</name> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </parameter> <parameter> <name>maxWait</name> <value>5000</value> </parameter> <parameter> <name>username</name> <value>Andrew</value> </parameter> <parameter> <name>password</name> <value>12345</value> </parameter> </ResourceParams> Then, once I get the DataSource, then the connection, I do a setCatalog() to define the correct DB. - Andrew -----Original Message----- From: Turner, John [mailto:[EMAIL PROTECTED]] Sent: Friday, July 12, 2002 3:37 PM To: '[EMAIL PROTECTED]' Subject: JNDI and/or pooling help (long post) Hello - I'm having problems getting a connection to my database using JNDI and various pooling mechanisms. I'm using tomcat 4.0.3 standalone on Win2K. First, let me say that I can access my database (SQL Server 2000) using the Microsoft JDBC Type 4 driver without any problems if I put the connection code right in my servlet (Class.forName, etc.). If I do that, no problems. It's only when I try and move the database connection code up to an application scope or use pooling that I run into problems. I've setup JNDI according to the Jakarta-Tomcat HOW-TO. I've tried DBCP/pool according to this link: http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2 I also tried the solution from here: http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBo ok/c onpool.html And I also tried the DBConnectionBroker from javaexchange.com, as well as the DataSourceWrapper/ConnectionPool classes from the O'Reilly JSP book. I've even tried setting up DriverName, URL, username, and password as servlet parameters in web.xml and writing an "init" servlet that would read them in, create the datasource, and then push the datasource into the application scope with getServletContext().setAttribute(). That didn't work, either. I would definitely appreciate any help or suggestions, I'm going crazy trying to figure out what is wrong. I don't really even need the pooling, but what I want to do is get the specific database parameters (username, password, host, etc.) OUT of the servlets (and beans). I want other developers to just be able to grab a handle to the datasource, open a connection, and use it without having to know any specific information about the database and the parameters. Here's my server.xml (with the DBCP/pool) setup: <Resource name="jdbc/MyTestDB" auth="Container" type="javax.sql.DataSource" /> <ResourceParams name="jdbc/MyTestDB"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter><name>maxActive</name><value>100</value></parameter> <parameter><name>maxIdle</name><value>30000</value></parameter> <parameter><name>maxWait</name><value>100</value></parameter> <parameter> <name>user</name> <value>some_user</value> </parameter> <parameter> <name>password</name> <value>some_password</value> </parameter> <parameter> <name>databasename</name> <value>some_db</value> </parameter> <parameter> <name>driverClassName</name> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </parameter> <parameter> <name>url</name> <value>jdbc:microsoft:sqlserver://SOMEHOST:1433;User=some_user;Password= some _password;DatabaseName=some_db</value> --> </parameter> </ResourceParams> Here is my web.xml: <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/MyTestDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> In every case above, regardless of the pooling mechanism, or even just trying to setup a datasource as an application scope object, I get either an error message, or null. In the config above, I get null. The code I use with the config above looks like this: As a test, I wrote a little JNDI reader servlet that just enumerates over the JNDI space and lists out the objects: try { Context initCtx = new InitialContext(); NamingEnumeration enum = initCtx.listBindings("java:comp/env/jdbc"); while (enum.hasMore()) { Binding binding = (Binding) enum.next(); out.println("Name: " + binding.getName() + "<br>"); out.println("Type: " + binding.getClassName() + "<br>"); out.println("Value: " + binding.getObject() + "<br>"); out.println(); out.println(); } } catch (NamingException e) { out.println("Naming Exception: " + e.getMessage()); } When I run this servlet, I get output that says: Name: MyTestDB Type: org.apache.naming.ResourceRef Value: Reference Class Name: javax.sql.DataSource Type: description Content: DB Connection Type: scope Content: Shareable Type: auth Content: Container Now, I'm no expert by any means, but it seems to me that things are setup correctly, though I realize my JNDI reader servlet is just reading web.xml. JNDI knows what's up, or seems to, but for some reason I can't get a valid DataSource to my database. Any thoughts? Suggestions? I can't switch databases, and I can't buy another Type 4 driver (the Microsoft driver is free), nor can I use the JDBC-ODBC bridge. Any help is appreciated!! - John ============================================ John Turner [EMAIL PROTECTED] | 248-488-3466 Advertising Audit Service http://www.aas.com - John ============================================ John Turner [EMAIL PROTECTED] | 248-488-3466 Advertising Audit Service http://www.aas.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>