我將描述環境第一javax.naming.NameNotFoundException:名稱[jdbc/eswastha]未在此上下文中綁定。無法找到[JDBC]
環境::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="[email protected]*" />
和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;
}
}
請幫我找出問題。
Regards
希望這會幫助別人,http://stackoverflow.com/questions/12484759/apache-tomcat-7-0-30- datasourcerealm-javax -naming-namenotfoundexception-name-j/23469293#23469293 – NoNaMe