JDBC

Study/JAVA 2012. 8. 27. 14:04

JDBC는 자바 언어를 통해서 DBMS와 무관하게 어디에서든지 사용할 수 있는 API라고 볼 수 있다

프로그래 작성 순서도

1. JDBC 드라이버 로드

ex) MySQL 에서 Connector/J 드라이버를 로드하는 경우

Class.forName("org.gjt.mm.mysql.Driver").newInstance()

ex) ODBC 브리지를 로드하는 경우

Class.forName("sun.jdbc.odbcjdbcOdbcriver");

ex) Class.forName("com.ashna.jturbo.driver.Driver").newInstance();

 

2. 커넥션 열기

ex) MySQL에서 Connector/J 드라이버를 사용하는 경우

String url = "jdbc:mysql://localhost:1111/contacts";

Connection con = DriverManager.getConnection(url, "user=id", "password");

ex) MS-SQL에서 JTurbo 드라이버를 사용하는 경우

String url = "jdbc:JTurbo://localhost:1111/contacts";

Connection con = DriverManager.getConnection(url,"sa","");

 

3. SQL 전송

ex) excuteUpdate() 사용하는 경우

Statement stmt = con.createStatement();

int r = stmt.excuteUpdate("create table frined();

rc = stmt.executeIpdate("insert into friend values();

ex) executeQuery()

Statemnt stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("select * from friends");

 

4. 컨넥션을 닫는다

rs.close();

stmt.close();

con.close();

'Study > JAVA' 카테고리의 다른 글

Substring  (0) 2012.08.28
JDBC 관련 클래스  (0) 2012.08.27
== 와 equals()  (0) 2012.08.27
java.lang.NullPointerException 에러  (0) 2012.08.17
annotation  (1) 2012.08.03
Posted by 코딩하는 야구쟁이
,