我有一个 SQL 查询,我想用它来将组件计数到表中。
private DCDataObj dc;
public class DCDataObj
{
private int datacenter; // Datacenters
..............
public DCDataObj(int datacenter............)
{
this.datacenter = datacenter;
...............
}
public int getDatacenter()
{
return datacenter;
}
public void setDatacenter(int datacenter)
{
this.datacenter = datacenter;
}
............
}
ps = conn.prepareStatement("SELECT COUNT(1) AS CNT FROM COMPONENTSTATS CS, COMPONENTTYPE CT "
+ " WHERE CS.COMPONENTTYPEID = CT.COMPONENTTYPEID AND CT.COMPONENTTYPEID IN ( "
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " // 10
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " // 20
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " // 30
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) " // 40
+ " GROUP BY CT.NAME ORDER BY CT.NAME");
ps.setInt(1, 1000);
...............
ResultSet result = ps.executeQuery();
while (result.next())
{
dc = new DCDataObj(
result.getInt(1),
...............
这是完整的源代码: http: //pastebin.com/YMvqBPpV
我收到此错误消息:java.sql.SQLException: Invalid column index
这是设计问题还是问题出在 SQL 查询中?