SQLite官方的JDBC驱动程序,示例程序
importjava.sql.*;publicclassTest{publicstaticvoidmain(String[]args)throwsException{Class.forName("org.sqlite.JDBC");Connectionconn=DriverManager.getConnection("jdbc:sqlite:test.db");Statementstat=conn.createStatement();stat.executeUpdate("droptableifexistspeople;");stat.executeUpdate("createtablepeople(name,occupation);");PreparedStatementprep=conn.prepareStatement("insertintopeoplevalues(?,?);");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);ResultSetrs=stat.executeQuery("select*frompeople;");while(rs.next()){System.out.println("name="+rs.getString("name"));System.out.println("job="+rs.getString("occupation"));}rs.close();conn.close();}}点击空白处退出提示
评论