首先下载驱动
官网链接:http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
打开idea
第一步:右边 数据源
(如果没有显示单击这里,有就不需要了)
第二步:导入包
第三步:创建sqlite(最好放在项目的目录下)
ok后创建成功
第四步:创建表
sql代码如下
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
create table peop(id int,name varchar(10),age int); insert into peop values (1,'韦邦杠1',18); insert into peop values (2,'韦邦杠2',19); insert into peop values (3,'韦邦杠3',20); select * from peop;
创建成功,查看
第五步:导入包
第六步:进行对接
链接地址也可以这样
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com; import java.sql.*; public class Test { public static void main(String[] args) { Connection conn = null; ResultSet rs = null; Statement statement = null; try { Class.forName("org.sqlite.JDBC");//驱动 conn = DriverManager.getConnection("jdbc:sqlite:E:\sqlite3test\my.sqlite"); statement = conn.createStatement(); rs = statement.executeQuery("SELECT * FROM peop"); while (rs.next()){ System.out.println("--------------------"); System.out.print("id:"+rs.getString("id")); System.out.print(" name:"+rs.getString("name")); System.out.println(" age:"+rs.getString("age")); } }catch (ClassNotFoundException ex){ System.out.println(ex.getMessage()); ex.printStackTrace(); } catch (SQLException sqlex){ System.out.println(sqlex.getMessage()); sqlex.printStackTrace(); } finally { try { rs.close(); statement.close(); conn.close(); } catch (Exception e){ System.out.println(e.getMessage()); } } } }