String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
오류가 발생한 구문은 요즘 자바 버전은 실행이 되지 않아도 됩니다.
try { 즉 해당 구문이 에러나거나 실행이 되지 않아도 되기 때문에 } catch(Exception) { } 구조로 다음 라인을 실행하여 정상 수행이 됩니다.
import java.sql.*; public class Test_JDBC { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { //String driver = "com.mysql.jdbc.Driver"; //Class.forName(driver); conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql", "root", "열려라참께"); stmt = (Statement)conn.createStatement(); String sql = "select 1"; rs = stmt.executeQuery(sql); if(rs.next() == true) { System.out.println(rs.getInt(1)); } if(rs != null) rs.close(); if(stmt != null) stmt.close(); if(conn != null) conn.close(); } catch(Exception e) { e.printStackTrace(); } finally { try { if(rs != null) rs.close(); if(stmt != null) stmt.close(); if(conn != null) conn.close(); } catch(SQLException e) { e.printStackTrace(); } } } }