IT/Java
MySQL 과 연동 하기
인러너
2018. 5. 18. 11:01
MySQL 에서 다운 받은 bin 파일을
jre - bin 파일 아래에 넣어준다.
프로젝트에서 우클릭 - properties - Java Build Path - Libraries 탭 - Modulepath -옆 Add External JARs..클릭;
그리고 밑에 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import java.sql.*; public class Conntest { public static void main(String[] args) { // TODO Auto-generated method stub try { //DB연결구문 Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://Localhost:3306/sample", "root", "0000"); System.out.println("OK, Connection"); conn.close(); } catch(ClassNotFoundException ce) { System.out.println("DB Driver Error"); } catch(SQLException e) { System.out.println("SQL 실패"); } } } | cs |