NAame jdbc is not bound in this Context : jdbc와 매칭이 안되는 오류
매칭이름은 xxxx.jndiName=java:comp/env/jdbc/qqqq이런식으로 설정되어있다.
java:comp/env/ 까지는 기본이름이며 jdbc/qqqq 가 JNDI Name 속성이었던 것.
web,xml에
<resource-ref>
<res-ref-name>jdbc/yyyy</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
res-type는 어떤 데이터베이스를 쓰느냐에 따라 달라짐.
------------------------------------------------------------------------------------------------------------------------------------------------------
아래는 예시임.
1. server.xml
<host>
..
..
<Context path="/test" docBase="D:\workspace\test\testRoot"
<Resource name="jdbc/qqqq" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="test" password="test1234" driveClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@//localhost:1521/XE" />
</Context>
</host>
1-1. path="/" 부분은 http://localhost:8080/test 라고 호출
1-2. docBase="" 실제 프로젝트가 존재하는 경로.
1-3. username/password DB접속 정보
2. web.xml
<resource-ref>
<description>Oracle Development Datasource</description>
<res-ref-name>jdbc/qqqq</res-ref-name>
<res-type>oracle.jdbc.pool.OracleDataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. DbConnection.java
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class DbConnection{
public static Connection getConnection() throws SQLException{
Connection conn=null;
try{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/qqqq");
conn = ds.getConnection();
}catch(Exception e){
System.out.println(e);
}
return conn;
}
}
'Error > JSP' 카테고리의 다른 글
[15.11.19]Error : NAame jdbc is not bound in this Context 참고자료 (0) | 2018.01.02 |
---|