반응형
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | package stairsNoise; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.junit.Test; public class MySqlTest { Connection conn = null; Statement stmt = null; private final String DRIVER = "com.mysql.jdbc.Driver"; private final String URL = "jdbc:mysql://localhost:3307/jianDB?useSSL=false&serverTimezone=UTC"; private final String USER ="root"; private final String PW = "U3cnc@12345"; @Test public void test() { String sql; try { Class.forName(DRIVER); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(URL, USER, PW); System.out.println(">> 연결 성공"); stmt = conn.createStatement(); sql = "SELECT SNO, ID, PW, TITLE, CONTENTS, REG_DATE FROM JIANBOARD"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ String title = rs.getString("title"); System.out.println(" title >> " + title); } rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ } try{ if(conn!=null) conn.close(); }catch(SQLException se){ se.printStackTrace(); } } } } | cs |
반응형
'Programming Language > Java' 카테고리의 다른 글
[Java] System.nanoTime() 이용하여, 함수 실행 시간 log를 남기고 싶을 때는? (0) | 2018.09.06 |
---|---|
[Java] java:comp/env/jdbc/DefaultDS 란 (스크랩) (0) | 2018.07.05 |
[Java] retainAll() 로 두 list의 중복 요소 제거 (0) | 2018.06.14 |
[Java] 자바 인코딩 new String( ... , 'EUC-KR') (0) | 2018.05.29 |
[JAVA] Referer로 이전 페이지 주소 알아내기 (0) | 2018.05.25 |