我正在使用 SQLite JDBC 驱动程序访问数据库,由于某种原因,如果数据库中没有行,应用程序就会终止,并且几乎没有解释为什么会发生这种情况。
如果数据库不为空,则工作正常;
这是终止发生的地方:
public static CustomFillTable Select(String table, String[] column, Object operand) throws SQLException
{
Connection connection = null;
PreparedStatement ps = null;
try
{
StringBuilder query = new StringBuilder();
query.append("select ");
for(int i = 0; i < column.length; i++)
{
query.append(column[i]);
if(i < column.length -1)
{
query.append(",");
}
}
query.append(" from ");
query.append(table);
//Verify usage of where clause
if(operand != null)
{
query.append(" where ");
query.append(operand);
}
//Termination occurs here
connection = DriverManager.getConnection(_connectionString);
connection.setAutoCommit(false);
ps = connection.prepareStatement(query.toString());
ResultSet rs = ps.executeQuery();
connection.commit();
CustomFillTable model = new CustomFillTable(rs);
while(rs.next())
{
System.out.println("id = " + rs.getString("id"));
System.out.println("name = " + rs.getString("name"));
}
return model;
}
应用程序在 DriverManager.getConnection 行关闭,我发现这与数据库是否填充无关。
有人知道如何解决这个问题吗?我已经发布了日志转储信息here .
编辑:
连接字符串 -
“jdbc:sqlite:D:\Documents\Uni\Semester 2\Languages、平台和工具\Assignment\Java\SQLiteAssignment\mydatabasefile.db”
最佳答案
查看供应商网站后,似乎这个问题已在以后的版本中得到解决。无论如何,我最终还是更换了驱动程序,但我认为这可能对人们有用。
关于数据库为空时 Java 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872509/