我有一个查询在SQLyog中运行良好,但不在eclipse中。我调试时显示的错误是“找不到列”。sql查询在eclipse中不起作用
这里是我的查询:
String searchQuery = "select AVG(Rating) from rating where CoursesID=? and MONTH(dtDate)=? group by dtDate";
表:
ID | CoursesID | Rating | Comment | dtDate
11111 | SKM3207 | 5 | No | 2015-05-20
的Java
//preparing some objects for connection
Connection currentCon = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
//double totalRate = 0.0;
Vector<String> monthRating = new Vector<String>();
try{
String searchQuery = "select AVG(Rating) from rating where CoursesID=? and MONTH(dtDate)=? group by dtDate";
//connect to DB
currentCon = ConnectionManager.getConnection();
pstmt=currentCon.prepareStatement(searchQuery);
pstmt.setString(1, CoursesID);
pstmt.setString(2, fmonth);
rs = pstmt.executeQuery();
while(rs.next()){
monthRating.add(rs.getString("Rating"));
//String avg = rs.getString(1);
//totalRate = Double.parseDouble(avg);
}
}
catch (Exception ex){
System.out.println("Log In failed: An Exception has occurred! " + ex);
}
//some exception handling
finally{
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e) {}
pstmt = null;
}
if (currentCon != null) {
try {
currentCon.close();
} catch (Exception e) {
}
currentCon = null;
}
}
return monthRating;
是,任何需要添加到其中,因此它可以在Eclipse中运行?
请出示你的表 –
什么你连接字符串到数据库看起来像? –
检查你的表'create'语句 – Kushal