:: Tomcat 설정 파일 context.xml 에 추가

<Resource
	auth="Container"
	driverClassName="oracle.jdbc.driver.OracleDriver"
	name="jdbc/Oracle11g"
	type="javax.sql.DataSource"
	url="jdbc:oracle:thin:@localhost:1521:xe"
	username="publicvoid"
	password="privatevoid"
	maxActive="50"
	maxWait="500"
/>
Markup

:: 사용 예시

public class ContentDao {

	private DataSource dataSource;

	public ContentDao() {
		try {
			Context context = new InitialContext();
			dataSource = (DataSource)context.lookup("java:comp/env/jdbc/Oracle11g");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public ArrayList<ContentDto> list() {
		ArrayList<ContentDto> ContentDtos = new ArrayList<ContentDto>();

		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			conn = dataSource.getConnection();
			String query = "SELECT * FROM TEST_BOARD";
			pstmt = conn.prepareStatement(query);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				// ...
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) rs.close();
				if (pstmt != null) pstmt.close();
				if (conn != null) conn.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return ContentDtos;
	}
}
Java

위와 같이 찾을 수 없다는 오류가 나오면 JSTL을 다운로드하여 설치하면 된다.

다운로드 : https://tomcat.apache.org/taglibs.html



C:\Java\jre1.8.0_162\lib\ext 등과 같은 외부 라이브러리 폴더에 넣어주면 된다.

:: JDBC 드라이버 복사
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib 폴더 안에 ojdbc6_g.jar 파일을
C:\Java\jre1.8.0_162\lib\ext 로 복사

:: 간단한 사용 예시
Connection connection;
Statement statement;
ResultSet resultSet;

String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String uid = "publicvoid";
String upw = "privatevoid";
String query = "select * from void_members";

try {
	Class.forName(driver);
	connection = DriverManager.getConnection(url, uid, upw);
	statement = connection.createStatement();
	resultSet = statement.executeQuery(query);

	while (resultSet.next()) {
		String id = resultSet.getString("user_id");
		String pw = resultSet.getString("user_pw");
		String name = resultSet.getString("user_name");
		String mobile = resultSet.getString("user_mobile");
		out.println("아이디 : " + id + " / 패스워드 : " + pw + " / 이름 : " + name + " / 휴대전화 : " + mobile);
	}
} catch (Exception exception) {
	exception.printStackTrace();
} finally {
	try {
		if (resultSet != null) resultSet.close();
		if (statement != null) statement.close();
		if (connection != null) connection.close();
	} catch (Exception exception2) {
		exception2.printStackTrace();
	}
}
Java
:: POST
프로젝트 web.xml 파일 <wep-app> 태그내에 다음 내용 추가
<filter>
	<filter-name>encodingFilter</filter-name>
	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
	<init-param>
		<param-name>encoding</param-name>
		<param-value>UTF-8</param-value>
	</init-param>
	<init-param>
		<param-name>forceEncoding</param-name>
		<param-value>true</param-value>
	</init-param>
</filter>

<filter-mapping>
	<filter-name>encodingFilter</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>
Markup


:: GET
톰캣 server.xml 파일 Connector 에 URIEncoding 속성추가하여 다음과 같이 수정
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8181" protocol="HTTP/1.1" redirectPort="8443"/>

<Connector URIEncoding="UTF-8" port="8009" protocol="AJP/1.3" redirectPort="8443"/>
Markup