톰캣 my sql 연결 정보

tomcat.apache.org/tomcat-8.5-doc/jndi-datasource-examples-howto.html#MySQL_DBCP_2_Example

 

Apache Tomcat 8 (8.5.56) - JNDI Datasource How-To

JNDI Datasource configuration is covered extensively in the JNDI-Resources-HOWTO. However, feedback from tomcat-user has shown that specifics for individual configurations can be rather tricky. Here then are some example configurations that have been poste

tomcat.apache.org

 

 

my sql 연결 라이브러리

mysql-connector-java-5.1.39-bin.jar
0.94MB

 

 

web.xml

<!-- 	mysql -->
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

위 코드 추가

 

 

context.xml

<Context>

  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxTotal="100" maxIdle="30" maxWaitMillis="10000"
               username="bitc" password="bitc5600" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/test_sch"/>

</Context>

위 코드 추가 (아이디 비밀번호 url을 체크한다)

 

 

DBconn 관련 자바파일

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

jdbc/TestDB에 연결 해준다.

 

 

'Database > MySQL' 카테고리의 다른 글

mysql 외래키 foreign key 설정  (0) 2020.06.24
mysql 시퀀스 auto_increment 생성 초기화  (0) 2020.06.23
mysql ssl 오류 났을 경우  (0) 2020.06.23
mysql 세팅  (0) 2020.06.19
mySQL 설치  (0) 2020.06.19

+ Recent posts