mysql 연동하기

2016. 9. 6. 17:44프로그래밍/jsp

반응형

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

    pageEncoding="UTF-8" import="java.sql.*" %>                             <!-- import를 추가로 넣어준다 -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

<%

  

        String driver="com.mysql.jdbc.Driver";

String url="jdbc:mysql://127.0.0.1:3306/test?useSSL=true";

try{

Class.forName(driver);

Connection conn = DriverManager.getConnection(url,"root","mysql");

if (conn != null){

out.println("연결 성공");

conn.close();

} else out.println("연결 실패");

conn.close();

}  catch(Exception e) { System.out.println(e.getMessage());}



%>



</body>

</html>


반응형