1

このクエリをSQL Developerで実行すると、Person Pers_IDの最小作成タイムスタンプを持つレコードが返され、同じクエリはJava JDBC接続から値を返しません。

助けていただけますか?

select PERS_ID,CODE,BEG_DTE 
from PRD_HIST H 
where PERS_ID='12345'
and CODE='ABC'
and CRTE_TSTP=(
  select MIN(CRTE_TSTP) 
  from PRD_HIST S 
  where H.PERS_ID=S.PERS_ID 
  and PERS_ID='12345' 
  and EFCT_END_DTE is null
)

Java コード

 public  static List<String[]> getPersonwithMinCreateTSTP(final String PERS_ID,final String Category,final Connection connection){
    final List<String[]> personRecords = new ArrayList<String[]>();
    ResultSet resultSet = null;
    Statement statement = null;
    String PersID=null;
    String ReportCode=null;
    String effBegDate=null;

    try{
    statement = connection.createStatement();
    final String query="select PERS_ID,CODE,EFCT_BEG_DTE from PRD_HIST H where PERS_ID='"+PERS_ID+"'and CODE='"+Category+"'and CRTE_TSTP=(select MIN(CRTE_TSTP) from PRD_HIST S where H.PERS_ID=S.PERS_ID and PERS_ID='"+PERS_ID+"' and EFCT_END_DTE is null)";

if (!statement.execute(query)) {
          //print error
        }
        resultSet = statement.getResultSet();
    while (resultSet.next()) {
    PersID=resultSet.getString("PERS_ID");
    ReportCode=resultSet.getString("CODE");
    effBegDate=resultSet.getString("EFCT_BEG_DTE");
    final String[] personDetails={PersID,ReportCode,effBegDate};
            personRecords.add(personDetails);
        }


    } catch (SQLException sqle) {
        CTLoggerUtil.logError(sqle.getMessage());
    }finally{ // Finally is added to close the connection and resultset
        try {
            if (resultSet!=null) {
                resultSet.close();
            }if (statement!=null) {
                statement.close();
            }
        } catch (SQLException e) {
                    //print error
        }
    }
        return personRecords;
}
4

3 に答える 3

1

Java プログラムから SQL SELECT ステートメントを印刷し、それを SQL*Plus に貼り付けて、何が起こっているかを確認します。変数を自分が思っているものに設定していない可能性があります。実際、SELECT ステートメントを実行せずに印刷すると、エラーが表示される可能性があります (大文字が必要な場合に小文字の値を使用するなど)。

それでも表示されない場合は、Java コードからの実際のクエリをここに投稿してください。

于 2011-11-04T21:12:40.637 に答える
0

データベース テーブルにはレコードがありますが、JDBC クライアントはレコードを取得できません。JDBC クライアントに選択権限がないことを意味します。コマンドラインで次のクエリを実行してください。

grant  all on emp to hr;
于 2016-11-15T16:39:38.580 に答える
0

私は同様の問題を抱えてここに来ました-次の他の人のために私のソリューションを投稿すると思っただけです-(sqlplusを介して)行った挿入の後に「COMMIT」を実行していませんでした-おお!

于 2014-10-11T12:38:50.873 に答える