【发布时间】:2013-02-21 09:30:15
【问题描述】:
我收到以下错误:
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: apartments)
实际上,该表确实存在。以下是我的代码:
try {
// load the sqlite-JDBC driver using the current class loader
Class.forName("org.sqlite.JDBC");
Connection connection = null;
// create a database connection
connection = DriverManager.getConnection("jdbc:sqlite:/Path/To/apartments.db");
System.out.println(connection.getMetaData());
Statement statement = connection.createStatement();
statement.setQueryTimeout(30);
ResultSet rs = statement.executeQuery("select * from apartments");
while(rs.next()) {
// read the result set
System.out.println("TEXT = " + rs.getString("display_text"));
System.out.println("X1 = " + rs.getInt("x1"));
}
} catch (Exception ex) {
Logger.getLogger(MouseEventDemo.class.getName()).log(Level.SEVERE, null, ex);
}
【问题讨论】:
-
它说 SQL error or missing database ,我猜这不是表问题
-
如何检查不会是路径问题?
-
我认为您将数据库名称与表名称混淆了。您的数据库名称是公寓和桌子的名称也一样吗?
-
我认为是路径问题。尝试在
getConnection()中给出完整路径 -
@FestusTamakloe 我的数据库名称是 main,我找不到提及数据库名称的方法。这是 SQLite
标签: java database sqlite sqlexception