Java SQLite行在执行select查询后消失
我正在为我的电影应用程序使用SQLite数据库和java servlet 我有一个与数据库通信的DAO。对数据库进行select查询后,随机行被删除 下面是一个基于电影的投影列表的方法,但每次调用它时,它都会以某种方式删除表中的行。(它总是删除顶部的行和之后的随机行)Java SQLite行在执行select查询后消失,java,sqlite,row,delete-row,Java,Sqlite,Row,Delete Row,我正在为我的电影应用程序使用SQLite数据库和java servlet 我有一个与数据库通信的DAO。对数据库进行select查询后,随机行被删除 下面是一个基于电影的投影列表的方法,但每次调用它时,它都会以某种方式删除表中的行。(它总是删除顶部的行和之后的随机行) 公共静态列表getAllByMovie(整数电影\u id){ 列表投影=新的ArrayList(); Connection con=ConnectionManager.getConnection(); PreparedState
公共静态列表getAllByMovie(整数电影\u id){
列表投影=新的ArrayList();
Connection con=ConnectionManager.getConnection();
PreparedStatement ps=null;
结果集rs=null;
试一试{
String query=“从投影中选择*,其中movie=?和dateandtime>='2020-02-11';
ps=合同准备陈述(查询);
ps.setInt(1,电影id);
SimpleDataFormat sdf=新的SimpleDataFormat(“yyyy-MM-dd-HH:MM”);
rs=ps.executeQuery();
while(rs.next()){
int指数=1;
intid=rs.getInt(index++);
int title=rs.getInt(index++);
int projection_type=rs.getInt(index++);
int战区_rs=rs.getInt(index++);
字符串日期和时间=rs.getString(index++);
双倍价格=rs.getDouble(指数+);
int admin_creator=rs.getInt(index++);
剧院=剧院道.get(剧院);
Movie Movie=MovieDAO.get(标题);
ProjectionType ProjectionType=ProjectionTypeDAO.get(投影类型);
投影=新投影();
投影。setId(id);
projection.setMovie(movie.getTitle());
projection.setProjectionType(projectionType.getName());
projection.setTheater(theater.getName());
Date Date=sdf.parse(日期和时间);
projection.setDateOutput(日期和时间);
投影。设置日期和时间(日期);
投影。设置票证价格(价格);
projection.setAdminCreator(管理员创建者);
增加(预测);
}
}捕获(例外情况除外){
例如printStackTrace();
}最后{
尝试{ps.close();}catch(异常ex1){ex1.printStackTrace();}
尝试{rs.close();}catch(异常ex1){ex1.printStackTrace();}
}
回报预测;
}
我总是通过这个查询得到想要的结果,但它会随机删除行
我有许多其他的数据库方法和查询,但没有一个调用这种行为
编辑:我得出结论,最初表中有25个投影(行),它会删除行,直到剩下15个!(前10行被删除,第一行然后随机删除其他9行)
到底发生了什么事?我有预感。你能展示一下调用getAllByMovie()DAO的调用方法吗?我想我已经弄明白了,我正在用cases进行切换,而getAllByMovie case在最后缺少break,所以它可能会转到下一个方法,即delete。。。
public static List<Projection> getAllByMovie(Integer movie_id) {
List<Projection> projections = new ArrayList<>();
Connection con = ConnectionManager.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String query = "SELECT * FROM projections WHERE movie = ? AND dateandtime >= '2020-02-11'";
ps = con.prepareStatement(query);
ps.setInt(1, movie_id);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
rs = ps.executeQuery();
while (rs.next()) {
int index = 1;
int id = rs.getInt(index++);
int title = rs.getInt(index++);
int projection_type = rs.getInt(index++);
int theater_rs = rs.getInt(index++);
String date_and_time = rs.getString(index++);
double price = rs.getDouble(index++);
int admin_creator = rs.getInt(index++);
Theater theater = TheaterDAO.get(theater_rs);
Movie movie = MovieDAO.get(title);
ProjectionType projectionType = ProjectionTypeDAO.get(projection_type);
Projection projection = new Projection();
projection.setId(id);
projection.setMovie(movie.getTitle());
projection.setProjectionType(projectionType.getName());
projection.setTheater(theater.getName());
Date date = sdf.parse(date_and_time);
projection.setDateOutput(date_and_time);
projection.setDateAndTime(date);
projection.setTicketPrice(price);
projection.setAdminCreator(admin_creator);
projections.add(projection);
}
} catch(Exception ex) {
ex.printStackTrace();
} finally {
try {ps.close();} catch (Exception ex1) {ex1.printStackTrace();}
try {rs.close();} catch (Exception ex1) {ex1.printStackTrace();}
}
return projections;
}