본문 바로가기
프로그래밍 놀이터/안드로이드, Java

Java SQLite Tutorial

by 돼지왕 왕돼지 2014. 9. 16.
반응형

 

1. JDBC jar 다운받기

 

https://bitbucket.org/xerial/sqlite-jdbc/downloads 

 

 

2. Classpath 에 jar 연결하기.

 

 

3. DB and table creation

 

Connection conn = null;

Statement stmt = null;

try {

Class.forName( "org.sqlite.JDBC" );

conn = DriverManager.getConnection( "jdbc:sqlite:test.db" );

stmt = conn.createStatement();

String sql = "CREATE TABLE test " +

"(_id INT PRIMARY KEY NOT NULL," +

" name TEXT NOT NULL, " + 

" image BLOB NOT NULL )"; 

stmt.executeUpdate(sql);

} catch ( Exception e ) {

System.err.println( e.getClass().getName() + ": " + e.getMessage() );

System.exit(0);

}

finally{

SQLiteUtils.close( stmt );

}

System.out.println("DB creation success.");

return conn;

 

 

4. Transactions

 

 

 

반응형

댓글