我正在开发一个Web服务。我以为我已经准备好发布我的第一个高效版本但是我一直在接受一个对我没有任何意义的SQLException。我正在针对Oracle db btw开发。 我先谈谈你的代码:
try{
variable = DoQuery("SELECT KEY FROM TABLE WHERE KEY IN ('KEY1', 'KEY2') AND ROWNUM = 1").getString("HANDLE");
}catch(SQLException e){
return "Wasn't able to gather key: " + e.toString() + " - " + e.getSQLState();
}
方法“DoQuery”:
private ResultSet DoQuery(String sqlString){
Statement sqlHandleStatement;
try {
sqlHandleStatement = getStatement();
return sqlHandleStatement.executeQuery(sqlString);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
方法“getStatement”:
private Statement getStatement() throws SQLException {
DataSource dataSource = null;
try {
dataSource = (DataSource) JNDIUtils.getInitialContext().lookup(JNDIUtils.DEFAULT_DATASOURCE);
} catch (NamingException e) {
e.printStackTrace();
}
Connection connection;
connection = dataSource.getConnection();
Statement statement;
statement = connection.createStatement();
return statement;
}
但是如果我执行我的SOAP请求,我会一直回来:
<SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns2:getNextRMANumberResponse xmlns:ns2="http://webservice.epm.com/">
<return>Wasn't able to gather key: java.sql.SQLException: ResultSet.next was not called - 99999</return>
</ns2:getNextRMANumberResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
错误消息:“无法收集密钥:java.sql.SQLException:未调用ResultSet.next - 99999”(与本文中给出的第一个代码段相比)
这是什么意思?我真的不明白为什么我应该执行“ResultSet.next”?!
提前致谢!
答案 0 :(得分:10)
你必须拨打&#34; next&#34;然后是&#34; getString&#34;用于将结果集的光标设置到第一行。
try{
ResultSet resuse = DoQuery("SELECT KEY FROM TABLE WHERE KEY IN ('KEY1', 'KEY2') AND ROWNUM = 1");
resuse.next();
variable = resuse.getString("KEY");
}catch(SQLException e){
return "Wasn't able to gather key: " + e.toString() + " - " + e.getSQLState();
}
最初光标位于第一行之前。
答案 1 :(得分:1)
是,来自ResultSet API:ResultSet对象维护一个指向其当前数据行的游标。最初,光标位于第一行之前。下一个方法将光标移动到下一行
答案 2 :(得分:0)
From Official JavaDoc: -
Moves the cursor forward one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
When a call to the next method returns false, the cursor is positioned after the last row. Any invocation of a ResultSet method which requires a current row will result in a SQLException being thrown. If the result set type is TYPE_FORWARD_ONLY, it is vendor specified whether their JDBC driver implementation will return false or throw an SQLException on a subsequent call to next.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
答案 3 :(得分:0)
Actually Resultset.next()
not extracted error coming means you not called explicitly that is you write like this your problem will be solved
first of all check resltset
is null or not
if(rs!=null){
while(rs.next()){
-------process the results
}//while loop
}//if