开发者

JDBC Problem wth select where query [duplicate]

This question already has answers here: ResultSet exception - before start of result set (6 answers) Closed 5 years ago.

My Code:

con = jdbc.connect();
        System.out.println("status of con"+con);
String query = " select * from BmgCPUTotalUsage where CPUserID='"+CPUserID+"' and MessageTypeID='"+MessageTypeID+"'";
        System.out.println(query);
        PreparedStatement st开发者_StackOverflow中文版atement = con.prepareStatement(query);
    ResultSet result = statement.executeQuery();
    System.out.println(result);
    int QuotaUsed=result.getInt("QuotaUsed"); 

Output:

   status of concom.mysql.jdbc.JDBC4Connection@182600f
     select QuotaUsed from BmgCPUTotalUsage where CPUserID='msdp' and MessageTypeID='SMS'
    com.mysql.jdbc.JDBC4ResultSet@16e1dd8
    java.sql.SQLException: Before start of result set.

Can anybody please say me how can I remove this exception.and fetch the QuotaUsed from the table.where QuotaUsed is an integer.


You really need to do more reading of the JDBC Tutorial, but briefly, try this:

ResultSet resultSet = statement.executeQuery();
if (resultSet.next() {
    int quotaUsed = resultSet.getInt("QuotaUsed"); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜