본문 바로가기

리눅스

[리눅스] tomcat mysql 연동

반응형

tomcat mysql 연동

 

# yum install mysql-connector-java

 

# rpm -ql mysql-connector-java

/etc/maven/fragments/mysql-connector-java

/usr/share/doc/mysql-connector-java-5.1.17

/usr/share/doc/mysql-connector-java-5.1.17/CHANGES

/usr/share/doc/mysql-connector-java-5.1.17/COPYING

/usr/share/doc/mysql-connector-java-5.1.17/docs

/usr/share/doc/mysql-connector-java-5.1.17/docs/README.txt

/usr/share/doc/mysql-connector-java-5.1.17/docs/connector-j.html

/usr/share/doc/mysql-connector-java-5.1.17/docs/connector-j.pdf

/usr/share/java/mysql-connector-java-5.1.17.jar

/usr/share/java/mysql-connector-java.jar

/usr/share/maven2/poms/JPP-mysql-connector-java.pom

 

# cp /usr/share/java/mysql-connector-java-5.1.17.jar /app/tomcat/instance1/lib/.

 

mysql 테스트 페이지

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

<%@ page import = "java.sql.*" %>

<%

    Connection conn = null;

    try{

        String url = "jdbc:mysql://localhost:3306/DB_NAME";//생성한 데이타베이스 이름을 넣는다.

        String id = "ID"; // db에 접속하는 계정

        String pw = "PW"; // db에 접속하는 계정의 비밀번호

 

        Class.forName("com.mysql.jdbc.Driver");

        conn=DriverManager.getConnection(url, id, pw);

        out.println("success");  // mysql에 연결되면 성공!!

    }catch(Exception e){

        out.println("fail"); // mysql에 연결 실패!!

    }

%>

 

원본URL : http://shary1012.tistory.com/107

 

728x90
반응형