选择查询后,Java sqlite行消失

时间:2017-04-13 03:00:55

标签: java sql sqlite select

我有一个由其他程序创建的sqlite db文件,并检查一切正常。

然后在执行select查询以获取某些数据之后,该行之后的某些行会消失。我尝试使用prepareStatement虽然它有效,但仍然存在。

我的代码

private ForecastTableItem selectItemPrepareStatement(String tableName, String columnName, String name) {
    ForecastTableItem item = null;
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {
        Class.forName("org.sqlite.JDBC");
        conn = DriverManager.getConnection("jdbc:sqlite:" + dbLocation);
        System.out.println("Selecting item from tableName: "+tableName + " of col: "+columnName + " : "+name);

        String query = "SELECT * FROM " + tableName + " WHERE " + columnName + "=? COLLATE NOCASE";
        pstmt = conn.prepareStatement(query);

        pstmt.setString(1, name);
        rs = pstmt.executeQuery();

        if (rs.next()) {
            if (tableName.equalsIgnoreCase("mainTable")) {
                item = new ForecastTableItem();
                item.setId(rs.getInt("Id"));
                item.setTitle(rs.getString("title"));
                item.setLink(rs.getString("link").toLowerCase());
                item.setPositionType(rs.getString("positionType"));
                item.setPackageName(rs.getString("packageName"));
                item.setCsvFilePath(rs.getString("csvFilePath"));
                item.setSubpackageName(rs.getString("subpackageName"));
                item.setTimeFrame(rs.getString("timeFrame"));
                item.setForecastDate(rs.getString("forecastDate"));
                item.setTargetDate(rs.getString("targetDate"));
            }

        }


    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally{
        if(pstmt != null) try{ pstmt.close();} catch(SQLException e){};                   
        if(rs != null) try{ rs.close();} catch(SQLException e){};
        if(conn != null) try{ conn.close();} catch(SQLException e){};
    }


    return item;
}

1 个答案:

答案 0 :(得分:-1)

在COLLATE NOCASE使用半列后

" SELECT * FROM" + tableName +"在哪里" + columnName +" =? COLLATE NOCASE;&#34 ;;