tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "JS" <sma...@dcs.kcl.ac.uk>
Subject Getting desperate!! javax.naming.NamingException username is required]
Date Thu, 10 Apr 2003 17:37:14 GMT
Hi there Guys,
I'm pretty desperate on this now.... been searching the archives for the
last 2 hours. Someone out there must know whats going on here.Your help is greatly appreciated.

I get the javax.naming.NamingException chucked out me saying a "username
is required" even though I have set this up in server.xmlThe line it moans about in my servlet
is highlighted below. Ive included
server.xml, web.xml and catalina.out.
Thanks again
JS

public class SetupServlet extends HttpServlet {

public void init(ServletConfig config)
 throws ServletException
{

//initialise the database connectionpool for the DCSCoreDB
 super.init(config);
 try {
	InitialContext initContext = new InitialContext();
	log("-initContext");
	if (initContext == null) log("BOOM - initContext = null");
	Context envContext = (Context)initContext.lookup("java:/comp/env");
	log("- envContext");
	if (envContext == null) log ("BOOM - No Context");

!!!!!!!!!!Dodgy line!!!!!!
DataSource ds = (DataSource)envContext.lookup("jdbc/StudentDB");
	log("- DataSource");
	if (ds != null) {
		Connection conn = ds.getConnection();
	        log("- Connection");
		if (conn != null) {
		log("- Connection OK");
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT * FROM tblStudents");
		if (rs.next()); {
		System.out.println(rs);
							}
		conn.close();
		log("- Connection close");
		}
		else
		log("- BOOM Datasource null");
		}								}
	catch (SQLException sqle) {
	sqle.printStackTrace();
	}
	catch (NamingException ne) {
	ne.printStackTrace();
	}
}

Catalina.out says this;
Java Web Services Developer Pack/1.0_01-fcs
javax.naming.NamingException: DbcpDataSourceFactory:  username is required
	at
	org.apache.naming.factory.DbcpDataSourceFactory.getObjectInstance(DbcpDataSourceFactory.java:208)
at
	org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:177)	at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:835)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
	at project.SetupServlet.init(SetupServlet.java:26)
	at
	org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:919)	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:811)


This is the relevant part of server.xml

<!-- Insert <Context> Elements Here As Needed -->
		<Context
			path="/mydcs"
			docBase="mydcs"
			debug="0">
				<Logger className="org.apache.catalina.logger.FileLogger"
						prefix="localhost_mydcs_log."
						suffix=".txt"
						timestamp="true"/>

				<!-- setup pool for the StudentDB -->
				<Resource name="jdbc/StudentDB"
						  auth="Container"
						  type="javax.sql.DataSource"/>

				<ResourceParams name="jdbc/StudentDB">
					<parameter>
						<name>factory></name>
						<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
					</parameter>

					<!-- set up pool parameters -->
					<parameter>
						<name>maxActive</name>
						<value>10</value>
					</parameter>
					<parameter>
						<name>maxIdle</name>
						<value>4</value>
					</parameter>
					<parameter>
						<name>maxWait</name>
						<value>10000</value>
					</parameter>

					<!-- setup database details -->
					<parameter>
						<name>username</name>
						<value>jason</value>
					</parameter>
					<parameter>
						<name>password</name>
						<value>pword</value>
					</parameter>
					<parameter>
						<name>driverClassName</name>
						<value>easysoft.sql.jobDriver</value>
					</parameter>
					<parameter>
						<name>url</name>
						<value>jdbc:easysoft:StudentDB</value>
					</parameter>

				</ResourceParams>

				<!-- Create another pool for DCSCore Database -->
				<Resource name="jdbc/DCSCoreDB"
						  auth="Container"
						  type="javax.sql.DataSource"/>

				<ResourceParams name="jdbc/DCSCoreDB">
					<parameter>
						<name>factory></name>
						<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
					</parameter>

					<!-- set up pool parameters -->
					<parameter>
						<name>maxActive</name>
						<value>10</value>
					</parameter>
					<parameter>
						<name>maxIdle</name>
						<value>4</value>
					</parameter>
					<parameter>
						<name>maxWait</name>
						<value>10000</value>
					</parameter>

					<!-- setup database details -->
					<parameter>
						<name>username</name>
						<value>jason</value>
					</parameter>
					<parameter>
						<name>password</name>
						<value>pword</value>
					</parameter>
					<parameter>
						<name>driverClassName</name>
						<value>easysoft.sql.jobDriver</value>
					</parameter>
					<parameter>
						<name>url</name>
						<value>jdbc:easysoft:DCSCoreDB</value>
					</parameter>

				</ResourceParams>


		</Context>

Web.xml is;
<!-- define resources used in webapp -->
	<resource-ref>
		<description>A resource reference to a factory for java.sql.Connection
		instances that are used to talk to the StudentDatabase that is configured
		in server.xml
		</description>
		<res-ref-name>jdbc/StudentDB</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

	<resource-ref>
		<description>A resource reference to a factory for java.sql.Connection
		instances that are used to talk to the DCSCoreDB databasee that is
		configured		in server.xml
		</description>
		<res-ref-name>jdbc/DCSCoreDB</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

-------- Original Message --------
Subject: [Fwd: javax.naming.NamingException username is required]
From: "JS" <smartt@dcs.kcl.ac.uk>
Date: Thu, April 10, 2003 5:23 pm
To: <tomcat-user@jakarta.apache.org>

Hi there,
I'm getting this error for some reason, and I have already defined the
parameters in server.xml. I also made a <resource-ref> parameter in
web.xml

Any one encountered this before?

Cheers
JS




--------------------------------------------------------------------- To
unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For
additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message