【问题标题】:JDBC Problem wth select where query [duplicate]选择 where 查询的 JDBC 问题 [重复]
【发布时间】:2011-08-27 20:00:11
【问题描述】:

我的代码:

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 statement = con.prepareStatement(query);
    ResultSet result = statement.executeQuery();
    System.out.println(result);
    int QuotaUsed=result.getInt("QuotaUsed"); 

输出:

   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.

谁能告诉我如何删除这个异常。并从表中获取 QuotaUsed。其中 QuotaUsed 是一个整数。

【问题讨论】:

  • 你有没有经历过接受答案的感觉?现在就试试。它确实很神奇。相信我。

标签: java jdbc


【解决方案1】:

您确实需要更多地阅读JDBC Tutorial,但简单来说,试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 2021-05-27
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多