2007년 5월 29일 화요일

java DB Connect 예제..

흠 한 번도 안 해봤는데..되려나?



java.sql.Connection은 어디서 가져와야 하나?









package com.stardeveloper.example; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class JdbcExample2 { public static void main(String args[]) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql:///test", "root", "secret"); if(!con.isClosed()) System.out.println("Successfully connected to " + "MySQL server using TCP/IP..."); } catch(Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if(con != null) con.close(); } catch(SQLException e) {} } } }

댓글 없음:

댓글 쓰기