-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dhiren,
On 3/9/2010 3:19 PM, Dhiren Bhatia wrote: > The Resource is defined as follows in the server.xml file: As Chuck suggests, move <Context> from server.xml to META-INF/context.xml in your webapp. > <Context path="/myapp" docBase="myapp" debug="0" > reloadable="true" > crossContext="true"> When you move <Context> as described above, remove both the "path" and "docBase" attributes. "debug" does nothing, BTW. > <Resource name="jdbc/myserver" auth="Container" > type="javax.sql.DataSource" /> Specifying java.sql.DataSource as the resource type means that Tomcat will create a org.apache.tomcat.dbcp.dbcp.BasicDataSource object. If you want a different type of object, you'll need to specify the /factory/ for the objects as well. Check the <Resource> documentation for how to do that. > <ResourceParams name="jdbc/myserver"> Again, as Chuck suggests, this is the long way of doing resource parameters. You can shove all this stuff into <Resource>, now. > <parameter> > <name>factory</name> > > <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> > </parameter> This might not work given the preference of <Resource> over <ResourceParams>. I'm not even sure if <ResourceParams> are used at all... Tomcat might be ignoring them. > </ResourceParams> I noticed that you didn't specify the username and password for the connection pool, here. Instead, you have it in your code: > import org.apache.commons.dbcp.BasicDataSource; > > private static BasicDataSource ds = null; > > Properties dbProps = new Properties(); > dbProps.load(new FileInputStream(dbConfFilePath)); > ds = (BasicDataSource) ctx.lookup("java:comp/env/" > + dbProps.getProperty(RESOURCE_NAME_KEY)); > ds.setDriverClassName(dbProps.getProperty(DRIVER_KEY)); > ds.setUrl(getJdbcUrl(dbProps)); > ds.setUsername(dbProps.getProperty(USERNAME_KEY)); > ds.setPassword(dbProps.getProperty(PASSWORD_KEY)); Why bother setting the driver class, url, username, and password in your webapp when the <Resource> element in context.xml can do it for you? You are just making your life more difficult by doing this. If you have a good reason to do this, let us know and we'll help you around it. Otherwise, I'd say just use context.xml to configure your DataSource and forget all the code you have above: just use javax.sql.DataSource to get connections that are already connected. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkuWuZgACgkQ9CaO5/Lv0PBj1gCgnvo863ZwGWGEjaOWMzqR66F9 u8AAnRw2ZlxplpU2+jaL6jO9qOfbexjC =0vjq -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org