라벨이 데이터베이스인 게시물 표시

JDBC

JDBC 작업 과정 1. 데이터베이스와 연결하는 드라이버 파일을 찾아서 객체를 발생시킨다. 2. 연결을 관리하는 Connection 객체를 생성한다. 4~6. 작업을 처리할 Statement 또는  PreperedStatement 또는  CallableStatement 객체를 생성한다. 7. 반환되는 결과는 int 또는 ResultSet 객체에 담는다. 8. 접속을 종료한다. 1 Class . forName ( "..." ); 2 Connection conn = DriverManager . getConnection ( "..." , "..." , "..." ); 3 // String url = "프로토콜:서브프로토콜:SID"; 4 Statement stmt = conn . createStatement (); //정적 쿼리 5 PreparedStatement prepStmt = conn . prepareStatement ( "..." ); //동적 쿼리 6 CallableStatement callStmt = conn . prepareCall ( "..." ); // 프로시저 처리 7 ResultSet result = stmt . executeQuery ( query ); 8 conn . close ();

SQLite JDBC

SQLite JDBC http://www.zentus.com/sqlitejdbc/ 사용법 1 import java . sql .*; 2 3 public class Test { 4 public static void main ( String [] args ) throws Exception { 5 Class . forName ( "org.sqlite.JDBC" ); 6 Connection conn = 7 DriverManager . getConnection ( "jdbc:sqlite:test.db" ); 8 Statement stat = conn . createStatement (); 9 stat . executeUpdate ( "drop table if exists people;" ); 10 stat . executeUpdate ( "create table people (name, occupation);" ); 11 PreparedStatement prep = conn . prepareStatement ( 12 "insert into people values (?, ?);" ); 13 14 prep . setString ( 1 , "Gandhi" ); 15 prep . setString ( 2 , "politics" ); 16 prep . addBatch (); 17 prep . setString ( 1 , "Turing" ); 18 prep . setString ( 2 , "computers" ); 19 prep . addBatch (); 20 prep . setString ( 1 , ...