码迷,mamicode.com
首页 > 数据库 > 详细

sqlite数据库在java中的使用

时间:2014-06-28 15:45:13      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   get   

bubuko.com,布布扣

bubuko.com,布布扣

/**
 * 
 */
package com.nyist.sqlitedemo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author yuchao
 * 
 * @school 南阳理工软件学院移动设备应用与开发
 *
 * @date  2014年6月19日 下午9:20:48
 */
public class SQLiteDemo {
   
     public static void main(String[] args) throws ClassNotFoundException, SQLException {
        
         Class.forName("org.sqlite.JDBC");
         Connection connection =DriverManager.getConnection("jdbc:sqlite:db/test.db");
         Statement statement=connection.createStatement();
         statement.executeUpdate("Drop Table if exists person");
         statement.executeUpdate("create table person(id int,name string)");
         statement.executeUpdate("insert into person values(1,‘yuchao1‘)");
         statement.executeUpdate("insert into person values(2,‘yuchao2‘)");
         statement.executeUpdate("insert into person values(3,‘yuchao3‘)");
         ResultSet rs =statement.executeQuery("select * from person");
         while(rs.next()){
             System.out.println("id=>"+rs.getInt("id")+",name=>"+rs.getString("name"));
         }
         statement.close();
         connection.close();
     }
}

 

运行结果:

id=>1,name=>yuchao1
id=>2,name=>yuchao2
id=>3,name=>yuchao3

 

sqlite数据库在java中的使用,布布扣,bubuko.com

sqlite数据库在java中的使用

标签:style   blog   http   java   color   get   

原文地址:http://www.cnblogs.com/yu0312chao/p/3798170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!