简体   繁体   English

IntelliJ从sqlite数据库文件中提取数据?

[英]IntelliJ extract data from sqlite database file?

I just started with sqlite and I stuck with a strange (maybe just for me) phenomenon. 我刚开始使用sqlite,但遇到了一种奇怪的现象(也许只是对我来说)。 When I connect the testDB.db file in java, and make one or some query, the data and the table itself is disappearing. 当我用Java连接testDB.db文件并进行一个或某些查询时,数据和表本身消失了。 The consol said that SQL error or missing database, and when I check the database file in cmd, the situation is really that; 控制台说SQL错误或数据库丢失,当我在cmd中检查数据库文件时,情况确实如此; there is no data in the file. 文件中没有数据。 Could anybody help me out with this basic problem? 有人可以帮我解决这个基本问题吗? (I suppose that this is just because of the lack of my knowledge in this topic, but I'm open to new information) (我想这仅仅是因为我对此主题缺乏了解,但是我愿意接受新的信息)

public class jdbcTest{

public static void main(String[] strg) {

    Connection connection = null;
    try {
        connection = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\Username\\Documents\\sqlite\\testDB");
        Statement statement = connection.createStatement();
        statement.setQueryTimeout(30);

        //statement.executeUpdate("drop table if exists person");
        ResultSet rs = statement.executeQuery("select * from company");
        while (rs.next()){
            System.out.print("id = "+rs.getInt("id")+"   ");
            System.out.println("name = "+rs.getString("name"));
        }
    }
    catch (SQLException e) {
        System.err.println(e.getMessage());
    }
    finally {
        try {
            if (connection!=null){
                connection.close();
            }
        }
        catch (SQLException e){
            System.err.println(e);
        }
    }
}

} }

When opening a nonexistent database file, SQLite will happily create a new, empty one. 当打开不存在的数据库文件时,SQLite会愉快地创建一个新的空文件。

The file name you're giving to getConnection does not actually point to the database you saved. 您为getConnection提供的文件名实际上并不指向您保存的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM