我有一個SQL查詢,我想用它來計算組件到表中。java.sql.SQLException:列索引無效
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:無效的列索引
是這個設計問題或問題是到SQL查詢?
您是否在'ps.setInt'或'result.getInt'處得到錯誤? – 2013-02-26 20:52:54
完整的堆棧跟蹤應該顯示問題所在的行。 – beny23 2013-02-26 20:53:50