Odd*_*Dev 6 java oracle soap sqlexception
我目前正在开发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();
}
Run Code Online (Sandbox Code Playgroud)
方法"DoQuery":
private ResultSet DoQuery(String sqlString){
Statement sqlHandleStatement;
try {
sqlHandleStatement = getStatement();
return sqlHandleStatement.executeQuery(sqlString);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
方法"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;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我执行我的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>
Run Code Online (Sandbox Code Playgroud)
错误消息:"无法收集密钥:java.sql.SQLException:未调用ResultSet.next - 99999"(与本文中给出的第一个代码段相比)
这是什么意思?我真的不明白为什么我应该执行"ResultSet.next"?!
提前致谢!
小智 11
您必须调用"next"然后调用"getString"函数将结果集的光标设置到第一行.
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();
}
Run Code Online (Sandbox Code Playgroud)
该API文档状态:
最初,光标位于第一行之前.