当前位置: 代码迷 >> J2SE >> jdbc怎么用代码创建sqlite数据库
  详细解决方案

jdbc怎么用代码创建sqlite数据库

热度:46   发布时间:2016-04-24 01:48:26.0
jdbc如何用代码创建sqlite数据库?
有做过的吗?说说api,谢谢。

------解决方案--------------------
添加 相关包然后
Java code
package sqlite;import java.sql.*;public class Test {    public static void main(String[] args) throws Exception {        Class.forName("org.sqlite.JDBC");        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");        Statement stat = conn.createStatement();        stat.executeUpdate("drop table if exists people;");        stat.executeUpdate("create table people (name, occupation);");        PreparedStatement prep = conn.prepareStatement(                "insert into people values (?, ?);");        prep.setString(1, "Gandhi");        prep.setString(2, "politics");        prep.addBatch();        prep.setString(1, "Turing");        prep.setString(2, "computers");        prep.addBatch();        prep.setString(1, "Wittgenstein");        prep.setString(2, "smartypants");        prep.addBatch();        conn.setAutoCommit(false);        prep.executeBatch();        conn.setAutoCommit(true);        ResultSet rs = stat.executeQuery("select * from people;");        while (rs.next()) {            System.out.println("name = " + rs.getString("name"));            System.out.println("job = " + rs.getString("occupation"));        }        rs.close();        conn.close();    }}
  相关解决方案