SQL错误或缺少数据库(无此表)

时间:2018-07-11 08:37:05

标签: java database sqlite

简单的代码,我不知道为什么它不起作用。一切都很好,但是如果我在文本字段中输入任何单词,这就是给出的输出:

[SQLITE_ERROR] SQL error or missing database (no such table: city)

我的数据库是SQLite Studio,而驱动器是jdbc-3.8.11.2.jar

数据库

public Connection connect() {

  try {

        conn = DriverManager.getConnection("jdbc:sqlite:‪‪‪inkingdom.sqlite");

        System.out.println("Connection to SQLite has been established.");

        return conn;
  } catch (SQLException e) {
        System.out.println(e.getMessage());  
        return null;
  }
}

在SQL中插入

@FXML
private void insertIntoAirport(ActionEvent event)  {

    try {

        pstmt = conn.prepareStatement("INSERT INTO city (airport) VALUES(?)");

        pstmt.setString(1, ccity.getText());

        pstmt.execute();
        pstmt.close();

    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }

}

1 个答案:

答案 0 :(得分:0)

首先创建表。

$ sqlite3 inkingdom.sqlite
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.
sqlite> create table city (airport text);

完成。