我将首先描述环境
环境::Netbeans 7.2 and Tomcat 7.0.27.0 is configured with Netbeans ID
当我单独进行构建并将其放在webapps
文件夹中并运行时,没有问题,但是当我在 IDE 本身中运行应用程序时,我得到javax.naming.NameNotFoundException: Name [jdbc/eswastha] is not bound in this Context. Unable to find [jdbc].
了这个异常。
conf/context.xml
<Resource name="jdbc/eswastha" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
url="jdbc:mysql://localhost:3306/eswastha"
driverClassName="com.mysql.jdbc.Driver"
username="root" password="r14@17*" />
和 web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jjdbc/eswastha</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
和java类:
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class JDBCManager {
public Connection mysqlConnection() {
Connection dbConnection = null;
try {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/eswastha");
dbConnection = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
return dbConnection;
}
}
请帮我确定问题。
问候