数据库
首页 > 数据库> > java操作sqlite数据库

java操作sqlite数据库

作者:互联网

第一步 添加依赖

maven依赖:

<dependency>
  <groupId>org.xerial</groupId>
  <artifactId>sqlite-jdbc</artifactId>
  <version>3.7.2</version>
</dependency>

第二步 编写代码

// 加载驱动
Class.forName("org.sqlite.JDBC");

Connection connection = null;

try {
    String questionContent = null;
    String options = null;
    String answers = null;

    // 获取连接
    connection = DriverManager.getConnection("jdbc:sqlite:/Users/root/Downloads/test.db");

    Statement statement = connection.createStatement();

    // 查询数据
    ResultSet resultSet = statement.executeQuery("select * from answers");
    while (resultSet.next()){
        questionContent = resultSet.getString("question_content");
        options = resultSet.getString("options");
        answers = resultSet.getString("answers");

        System.out.println("questionContent  " + questionContent);
        System.out.println("options  " + options);
        System.out.println("answers  " + answers);

    }
    // 关闭语句和连接
    statement.close();
    connection.close();
} catch (
        SQLException e) {
    e.printStackTrace();
}

标签:sqlite,java,数据库,resultSet,answers,null,questionContent,options
来源: https://blog.csdn.net/qq_34626094/article/details/121499374