我的代码:
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是一个整数。
答案 0 :(得分:8)
你真的需要更多地阅读JDBC Tutorial,但简单地说,试试这个:
ResultSet resultSet = statement.executeQuery();
if (resultSet.next() {
int quotaUsed = resultSet.getInt("QuotaUsed");
}