问题描述
此刻我正在开发Web服务.我以为我已经准备好发布我的第一个生产版本,但是我不断收到对我没有任何意义的SQLException.我正在针对Oracle db btw进行开发.首先让我给我我的代码:
I'm developing a Webservice at the moment. I thought I was ready to release my first productive version but I keep getting a SQLException which doesn't make any sense to me. I'm developing against a Oracle db btw.Let me give you my code at first:
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":
The method "DoQuery":
private ResultSet DoQuery(String sqlString){
Statement sqlHandleStatement;
try {
sqlHandleStatement = getStatement();
return sqlHandleStatement.executeQuery(sqlString);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
方法"getStatement":
The method "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请求,我会不断返回:
However if I execute my SOAP request I keep getting back:
<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"(与本文中给出的第一个代码段比较)
Error message: "Wasn't able to gather key: java.sql.SQLException: ResultSet.next was not called - 99999" (compare to the very first code snippet given in this post)
这是什么意思?我真的不明白为什么我应该执行"ResultSet.next"吗?
What does this mean? I really don't get why I should execute "ResultSet.next"?!
提前谢谢!
推荐答案
必须先调用"next",然后调用"getString"函数,才能将结果集的光标设置在第一行.
You must call "next" and then the "getString" function to set the resultset's cursor onto the first row.
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();
}
API文档指出:
这篇关于获取SQLException java.sql.SQLException:未调用ResultSet.next的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!