본문 바로가기

개발중/troubleshooting

자바 오라클 연동 에러(javax.naming.NameNotFoundException:)

728x90
반응형
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class MemberDAO {

	public MemberDAO() {
		// TODO Auto-generated constructor stub
	}
	
	private static MemberDAO instance = new MemberDAO();
	
	public static MemberDAO getInstance() {
		return instance;
	}
	
	public Connection getConnection() throws Exception {
		

		Connection conn = null;
		Context initContext = new InitialContext();
		Context envContext = (Context) initContext.lookup("java:/comp/env");
		DataSource ds = (DataSource) envContext.lookup("jdbc/myoracle");
		

		conn = ds.getConnection();
		

	
		return conn;
		
	}
}

 

자바를 연동해주는 객체를 만들고

 

<%@page import="java.sql.Connection"%>
<%@page import="member.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
try{
	MemberDAO memDao = MemberDAO.getInstance();
	Connection conn = memDao.getConnection();
	out.print("연동 성공");
}catch( Exception EX ){
	System.out.print(EX);
}

%>
</body>
</html>

호출하여 사용 하는데 자꾸만

 

javax.naming.NameNotFoundException:

 

이런 로그들이 뜨는 것이다

Name [jdbc/myoracle]은(는) 이 컨텍스트에 바인딩되지 않았습니다. [jdbc]을(를) 찾을 수 없습니다.

 

왜 찾을 수 없다는 것인가

책대로 했는데 ,, 답답해서 구글링을 해보니 원하는 답이 나오지 않았는데

 

package member;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class MemberDAO {

	public MemberDAO() {
		// TODO Auto-generated constructor stub
	}
	
	private static MemberDAO instance = new MemberDAO();
	
	public static MemberDAO getInstance() {
		return instance;
	}
	
	public Connection getConnection() throws Exception {
		

		  Connection CN = null;
		  Statement ST; 
		  PreparedStatement PST;
		  CallableStatement CST; 
		  ResultSet RS; 
		  java.util.Date Gwdate;
		  
		try{
			Class.forName("oracle.jdbc.driver.OracleDriver"); //드라이브로드
		    String url="jdbc:oracle:thin:@127.0.0.1:1521:XE" ;
		    CN = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","1234");
		    System.out.println("[ssi.jsp] Oracle Connected");
			}catch(Exception ex){System.out.println("Error name :" + ex);}
			ST = CN.createStatement();
		
	
		return CN;
		
	}
}

 학원에서 선생님이 가르쳐주신 방법인데 이렇게 하니까 되다니

 

더 자세히 기술해서 그런가?

 

 

 

 

아무튼 연동 성공!

 

728x90
반응형