자바 SQLite data 조회
1. 자바로 SQLite를 사용하기 위해서는 드라이버를 다운로드받고 프로젝트 Build Path에 External Library로 설치한다.
sqlite-jdbc-3.8.11.2
2. 자바 프로그램 작성
package test;
import java.sql.*;
public class DB_Read {
public static void main(String[] args) throws Exception {
Connection connection = null;
Statement statement = null;
try {
Class.forName("org.sqlite.JDBC");
}
catch(ClassNotFoundException e) {
System.out.println("org.sqlite.JDBC를 찾지못했습니다.");
}
connection = DriverManager.getConnection("jdbc:sqlite:c:/db/test2.db");
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM person");
while(resultSet.next()) {
System.out.printf("%s %s %s \n"
, resultSet.getInt("id")
, resultSet.getString("name")
, resultSet.getInt("age") );
}
resultSet.close();
connection.close();
}
}
3. 예상결과
1 홍길동 48
2 임꺽정 30