pool방식을 사용하여 연결했습니다.
jsp파일에서는 연결이 잘 되는데요
자바 컴파일 할려고 하니까 에러가 나네요..
톰켓 사용중입니다.
<에러 내용입니다>
MemberManager.java:22: unreported exception javax.naming.NamingException; must be caught or declared to be thrown
Context initContext = new InitialContext();
^
MemberManager.java:23: unreported exception javax.naming.NamingException; must be caught or declared to be thrown
DataSource ds = (DataSource) initContext.lookup(\"java:comp/env/jdbc/CUBRIDDS\");
<자바 소스입니다>
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.*;
import javax.naming.*;
public class MemberManager {
private static MemberManager instance = new MemberManager();
public static MemberManager getInstance() {
return instance;
}
private MemberManager() {
}
private Connection getConnection() throws SQLException {
Context initContext = new InitialContext();
DataSourceds = (DataSource) initContext.lookup(\"java:comp/env/jdbc/CUBRIDDS\");
return ds.getConnection();
}
....
<환경파일 셋팅한 값입니다>
-- conf/server.xml
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name=\"simpleValue\" type=\"java.lang.Integer\" value=\"30\"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name=\"UserDatabase\" auth=\"Container\"
type=\"org.apache.catalina.UserDatabase\"
description=\"User database that can be updated and saved\"
factory=\"org.apache.catalina.users.MemoryUserDatabaseFactory\"
pathname=\"conf/tomcat-users.xml\" />
*********추가부분******************
<Resource name=\"jdbc/CUBRIDDS\"
auth=\"Container\"
type=\"javax.sql.DataSource\"
driverClassName=\"cubrid.jdbc.driver.CUBRIDDriver\"
url=\"jdbc:cubrid:localhost:33000:jsp_test:::\"
username=\"test\" password=\"test\"
maxActive=\"10\"
maxIdle=\"10\"
maxWait=\"-1\"
removeAbandoned=\"true\"
removeAbandonedTimeout=\"60\"
logAbandoned=\"true\"/>
************************************
</GlobalNamingResources>
-- conf/context.xml
<Context reloadable=\"true\" >
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname=\"\" />
-->
<ResourceLink name=\"jdbc/CUBRIDDS\" global=\"jdbc/CUBRIDDS\" type=\"javax.sql.DataSource\" />
</Context>
-- 톰켓 Root/WEB_INF/web.xml
**** 추가 ****
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/CUBRIDDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
-- 그외..
혹시나 싶어서 etc/profile의 classpath쪽에 cubrid_jdbc.jar파일 연결했습니다.
|