我的代码:
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 是一个整数。
最佳答案
您确实需要多阅读 JDBC Tutorial ,但简单地说,试试这个:
ResultSet resultSet = statement.executeQuery();
if (resultSet.next() {
int quotaUsed = resultSet.getInt("QuotaUsed");
}
关于java - JDBC select where 查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6041334/