You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nicole Hibbard <nh...@xtelesis.com> on 2003/01/13 21:11:04 UTC
Name jdbc:comp is not bound in this context
I've gone through every resource I have in trying to test a connection to
MySql database.
I am using Tomcat 4.1.18-LE and MySql 3.23.53 and java 1.4.1_01.
I set priveleges on MySql, put the mm.sql driver's jar in common/lib.
I set my Classpath Variable
.;C:\ServletDev;C:\jakarta-tomcat-4.1.18-LE-jdk14\common\lib\servlet.jar;C:\
mysql-connector-java-2.0.14\mysql-connector-java-2.0.14-bin.jar
I added the following to my server.xml
<!--1/07/2002 Nicole Hibbard
The following block of code add the datasource for connecting
mysql database using Connector J Driver -->
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Logger className = "org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name = "jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!--Maximum number of dBconnections in pool. Make sure you configure your
mysqld max_connection large enough to handle all you connections-->
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>
<!-- Class name for JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<!-- The JDBC connection url for connecting to your mysql db
if the connection closes then auto connect -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/javatest?user=javauser</value>
</parameter>
</ResourceParams>
</Context>
<!--End of code from 1/7/2003 for Nicole Hibbard-->
I created a web.xml in DBTest/WEB-INF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//DN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>MySQL Test App </description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
I have a jsp in web-apps/DBTest
<html>
<head>
<title>DB Test</title>
</head>
<body>
<%
foo.DBTest tst = new foo.DBTest();
tst.init();
%>
<h2>Results</h2>
Foo <%= tst.getFoo() %><br/>
Bar <%= tst.getBar() %>
</body>
</html>
I have a DBTest.class in Webapps/DBtest/foo
package foo;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
String foo = "Not Connected";
int bar = -1;
public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =
(DataSource)ctx.lookup(
"java:comp/env/jdbc/TestDB");
if (ds == null) foo= "Datasource is null";
if (ds != null) {
Connection conn = ds.getConnection();
if (conn == null) foo="got datasource, no connection";
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select id, foo, bar from testdata");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
public String getFoo() { return foo; }
public int getBar() { return bar;}
}
AND I GET THE FOLLOWING ERROR ON TOMCAT
javax.naming.NameNotFoundException: Name jdbc:comp is not bound in this
Context
My test.jsp outputs
Results
Foo Not Connected
Bar -1
I have to get this working ASAP!! Please help!
Nicole
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Name jdbc:comp is not bound in this context
Posted by Nicole Hibbard <nh...@xtelesis.com>.
If someone doesn't have time to help me, but knows somewhere else I might be
able to get help, please let me know. If I don't get this working by
tonight then I'll probably have to nix using Tomcat alltogether and try
something different and I don't want that to happen. I appreciate any help
I can get.
Thanks,
Nicole
-----Original Message-----
From: Nicole Hibbard [mailto:nhibbard@xtelesis.com]
Sent: Monday, January 13, 2003 12:11 PM
To: tomcat-user@jakarta.apache.org
Subject: Name jdbc:comp is not bound in this context
I've gone through every resource I have in trying to test a connection to
MySql database.
I am using Tomcat 4.1.18-LE and MySql 3.23.53 and java 1.4.1_01.
I set priveleges on MySql, put the mm.sql driver's jar in common/lib.
I set my Classpath Variable
.;C:\ServletDev;C:\jakarta-tomcat-4.1.18-LE-jdk14\common\lib\servlet.jar;C:\
mysql-connector-java-2.0.14\mysql-connector-java-2.0.14-bin.jar
I added the following to my server.xml
<!--1/07/2002 Nicole Hibbard
The following block of code add the datasource for connecting
mysql database using Connector J Driver -->
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Logger className = "org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name = "jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!--Maximum number of dBconnections in pool. Make sure you configure your
mysqld max_connection large enough to handle all you connections-->
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>
<!-- Class name for JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<!-- The JDBC connection url for connecting to your mysql db
if the connection closes then auto connect -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/javatest?user=javauser</value>
</parameter>
</ResourceParams>
</Context>
<!--End of code from 1/7/2003 for Nicole Hibbard-->
I created a web.xml in DBTest/WEB-INF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//DN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>MySQL Test App </description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
I have a jsp in web-apps/DBTest
<html>
<head>
<title>DB Test</title>
</head>
<body>
<%
foo.DBTest tst = new foo.DBTest();
tst.init();
%>
<h2>Results</h2>
Foo <%= tst.getFoo() %><br/>
Bar <%= tst.getBar() %>
</body>
</html>
I have a DBTest.class in Webapps/DBtest/foo
package foo;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
String foo = "Not Connected";
int bar = -1;
public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =
(DataSource)ctx.lookup(
"java:comp/env/jdbc/TestDB");
if (ds == null) foo= "Datasource is null";
if (ds != null) {
Connection conn = ds.getConnection();
if (conn == null) foo="got datasource, no connection";
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select id, foo, bar from testdata");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
public String getFoo() { return foo; }
public int getBar() { return bar;}
}
AND I GET THE FOLLOWING ERROR ON TOMCAT
javax.naming.NameNotFoundException: Name jdbc:comp is not bound in this
Context
My test.jsp outputs
Results
Foo Not Connected
Bar -1
I have to get this working ASAP!! Please help!
Nicole
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>