我的单元测试对此查询工作正常,但是当我在本地运行我的应用时,它找不到列销售商。
String statement = "SELECT * FROM " + TABLE_NAME + " "
+ "INNER JOIN " + DbSeller.TABLE_NAME + " seller ON video.seller = seller.id "
+ "WHERE video.name LIKE ?";
//create statement
PreparedStatement stmt = DataBase.getInstance().prepareStatement(statement);
//set data
stmt.setString(1, "%" + s + "%");
//send query
ResultSet rs = stmt.executeQuery();
//the result
while(rs.next()) {
Video v = new Video();
System.out.println("test === " + rs.getInt("seller.id")); // <---- EXCEPTION (Column not found!!!!)
set(rs, v);
listVideo.add(v);
}
stmt.close();
如果我这样做,那很好:(只是为了测试我不希望最后逐列写出我需要的信息)
String statement = "SELECT video.*, seller.id as seller_id FROM " + TABLE_NAME + " "
+ "INNER JOIN " + DbSeller.TABLE_NAME + " seller ON video.seller = seller.id "
+ "WHERE video.name LIKE ?";
//create statement
PreparedStatement stmt = DataBase.getInstance().prepareStatement(statement);
//set data
stmt.setString(1, "%" + s + "%");
//send query
ResultSet rs = stmt.executeQuery();
//the result
while(rs.next()) {
Video v = new Video();
System.out.println("test === " + rs.getInt("seller_id")); // <---- NO EXCEPTION
set(rs, v);
listVideo.add(v);
}
stmt.close();
注意:我的应用程序在MySQL中的同一个脱机数据库上运行,所以唯一的区别是我通过我的应用程序运行此查询而不是单元测试。
答案 0 :(得分:-1)
列名seller_id
(下划线)和seller.id
(点)看起来与我不同