別のSPに渡すための出力パラメータを取得しようとしているため、テストを作成しましたが、その文字列を取得できるかどうかはわかりますが、例外はスローされます。SQL Serverストアドプロシージャの出力パラメータとResultSet値の両方を取得する
ます。java.sql.SQLException:無効状態は、ResultSetオブジェクトは、別の例外がスローされ
cs.getMoreResults();
なし
を閉じている:
java.sql.SQLException:出力パラメータはまだ処理されていません。 getMoreResults()を呼び出します。
私がif (rs.next()) {
を削除した場合は動作します。 出力パラメータを取得しても、私のif rs.next
は引き続き使用しますか?
protected String doInBackground(String... params) {
if (userid.trim().equals("Developer")|| password.trim().equals("Dev!n_234"))
isSuccess2=true;
z = getString(R.string.login_succes);
if(userid.trim().equals("")|| password.trim().equals(""))
z = getString(R.string.indsæt_rigtigt_bruger);
else {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = getString(R.string.Forbindelses_fejl) + "L1)";
} else {
String ID;
ID = setingPreferences.getString("companyid", "");
CallableStatement cs = null;
String query = "{ call [system].[usp_validateUserLogin](?,?,?,?,?)} ";
cs = con.prepareCall(query);
cs.setString(1, userid);
cs.setString(2, password);
cs.setString(3, ID);
cs.setBoolean(4, true);
cs.registerOutParameter(5, Types.VARCHAR);
ResultSet rs = cs.executeQuery();
cs.getMoreResults();
System.out.println("Test : " + cs.getString(5));
if (rs.next()) {
z = getString(R.string.login_succes);
isSuccess = true;
} else {
z = getString(R.string.Invalid_Credentials);
isSuccess = false;
}
}
}
catch (Exception ex)
{
isSuccess = false;
z = getString(R.string.Exceptions)+"L2)";
Log.e("MYAPP", "exception", ex);
}
}
return z;
}
}
が(HTTPS [文#getMoreResults' 'のjavadoc]を読む://ドキュメントを現在のResultSetを暗黙的に閉じます。 – bradimus
'csの代わりに' cs.execute() 'を呼び出してみてください。 executeQuery() ')を実行し、' cs.getString(5) 'から出力パラメータ値を取得できるかどうかを確認してください。 –
'cs.execute'は' ResultSet rs = 'と互換性がないので使用できませんが、もし 'if(rs.next()){'を取り除くと、私のコード内のもの? –