728x90
WAS에 jsp 모듈 설치
wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.23.tar.gz
tar zvxf mysql-connector-java-8.0.23.tar.gz
cd mysql-connector-java-8.0.23/
소스 설치하고 압축 해제
cp -a mysql-connector-java-8.0.23.jar /usr/lib/jvm/jre/lib/ext/
cp -a mysql-connector-java-8.0.23.jar /usr/local/tomcat8/lib/
jar 파일 복사
was 서버 설정
# /usr/local/tomcat8/conf/context.xml
<Context>
...
<Resource name="jdbc/testDB"
auth="Container"
type="javax.sql.DataSource"
username="was01"
password="q1w2e3!"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://10.0.180.56:3306/testDB"
maxActive="15"
maxIdle="3"/>
...
</Context>
name - jdbc/<DB이름>
username - DB에 접속할 DB계정
password - DB계정의 비밀번호
url - <DB 인스턴스 private IP>/:3306/<DB이름>
# /usr/local/tomcat8/conf/web.xml
<web-app>
...
<resource-ref>
<res-ref-name>jdbc/testDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
</web-app>
res-ref-name - jdbc/<DB이름>
DB 연동 화면 설정
# vi /usr/local/tomcat8/conf/web.xml
<%@ page import = "java.sql.*" %>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://10.0.180.56:3306/testDB";
Connection conn = DriverManager.getConnection(url, "was01", "q1w2e3!");
out.println("This is WAS01 page.<br>");
PreparedStatement ps=(PreparedStatement)conn.prepareStatement("SELECT * from color");
ResultSet rs=ps.executeQuery();
while(rs.next()){
String color=rs.getString("color");
String object=rs.getString("object");
out.println(color+"-"+object+"<br>");
}
}
catch(Exception e){
out.print(e.toString());
}
%>
systemctl restart tomcat8.service
바로 반영 안 될수도 있어서 restart 한 번 해준다.
새로고침하면 was01, was02가 번갈아가면서 잘 출력 된다
일주일 살살 녹았다
끗~٩( ᐛ )و
참고
https://honeywater97.tistory.com/94
728x90