2012-12-12 62 views
0

斐伊川傢伙!!!, 我已經寫在MySQL查詢這給特定字段的總和在表列和查詢是如何從MySQL表列中檢索特定字段的總和爲可變

PreparedStatement st = con.prepareStatement("SELECT COUNT(toc) AS std FROM processeddata_table where date(calldate) between '2009-01-01' and '2012-09-01' and toc='std' GROUP BY toc "); 

現在按照我的需要,我有所有的「性病」值的總和存儲到了,我已經寫了像

ResultSet res = st.executeQuery();  
while (res.next()) 
{ 
    int std=''; 
} 

如何獲得命名爲「性病」在變量字段的總和代碼變量。

夥計plz幫助我。 Thanx提前

回答

1

int std=res.getInt("std");應該得到的價值。

作爲每ResultSet javadoc

檢索以Java編程語言中int此ResultSet對象的當前行中指定列的值。

0
ResultSet res = st.executeQuery(); 
while (res.next()) 
{ 
    int std = res.getInt("std"); 
} 
0

您可以嘗試兩種下面的方法::

PreparedStatement st = con.prepareStatement("SELECT COUNT(toc) AS std FROM processeddata_table where date(calldate) between '2009-01-01' and '2012-09-01' and toc='std' GROUP BY toc "); 

方法1:由於空也約翰曾指出:

ResultSet res = st.executeQuery(); 
while (res.next()) 
{ 
    int std = res.getInt("std"); 
} 

方法2 ::

ResultSet res = st.executeQuery(); 
while (res.next()) 
{ 
    int std = res.getInt(1); 
} 
相關問題