1

Java プログラミングは初めてで、アプリケーションを C# から Java EE に移行しています。問題はこれです。ページ分割された結果を返すストアド プロシージャを介してクエリを実行します。たとえば、データベースで John という名前を検索するとします。クエリの結果は 10,000 件の John を返す可能性がありますが、ここでは 25 件の John のみを表示したいと考えています。したがって、私のストアド プロシージャは 2 つの結果を返します。1 つは John が検出した量、2 番目は John が選択した 25 個 (ページング) です。

私のC#コードでは次のとおりです。

            // Execute a stored procedure.
            DataSet dataSet = banco.ExecuteDataSet(command);
            if (dataSet != null)
            {
                // Check if something was retorned.
                if (dataSet.Tables.Count == 2)
                {
                    // Get the total of records found by query.
                    _totRegistros = (int)dataSet.Tables[0].Rows[0][0];

                        // Lê os dados da segunda tabela, que é a que contém os
                        // registros e preenche a página com os registros de detalhe.
                        bool impar = true;
                        foreach (DataRow row in dataSet.Tables[1].Rows)
                        {
                            // Salva os dados no registro da classe.
                            ReadDataRow(row);

                            // Inclui os registros de detalhe no formulário.
                            listagem += PrintLinGrid(impar);
                            impar = !impar;
                        }
                }
                else
                {
                    _temErro = true;
                    _msgUsuario = "Nenhum registro encontrado.";
                }

                // Libera área de memória alocada pelo DataSet.
                if (dataSet != null)
                {
                    dataSet.Dispose();
                    dataSet = null;
                }
            }

そして、ここで、Java での私のコード

    Connection con = Conexao.GetConnection();
    if (con != null) {
        // Create statement do execute stored procedure.
        CallableStatement stmt = null;
        try {
            // Insert de statament with stored procedure.
            stmt = con.prepareCall("{call BackOffice_Usuario_QueryPaginada(?,?,?,?,?,?,?)}",
                    ResultSet.TYPE_FORWARD_ONLY, 
                    ResultSet.CONCUR_READ_ONLY);

            // Add parameters to stored procedure.
            stmt.setString(1, "UsuarioId, UsuarioLojistaId, UsuarioStatusId, UsuarioTipoId,                    UsuarioNome, UsuarioCargo, UsuarioDepto, UsuarioCentroCusto, UsuarioLogin, UsuarioDataCadastro, UsuarioCriadoPorUsuarioId, UsuarioDataUltimoAcesso, UsuarioUltimaSessao, UsuarioAcessosAcumulados");                 
            stmt.setString(2, "Usuarios"); 
            stmt.setString(3, "1 = 1"); // Condition to teste
            stmt.setString(4, "UsuarioNome");
            stmt.setString(5, "ASC");
            stmt.setInt(6, 1);
            stmt.setInt(7, 25);

            // Execute stored procedure.
            ResultSet resultado = null;
            try {
                resultado = stmt.executeQuery();

                // This point is my problem, how can I do to translate
                //  _totRegistros = (int)dataSet.Tables[0].Rows[0][0]; and
                // foreach (DataRow row in dataSet.Tables[1].Rows) to java sintax?
                int x = 0;
                while(resultado.next()) {
                    x++;
                    System.out.println(x);

                    resultado.getRow();

                }
            } catch (SQLException e) {
                _temErro = true;
                _msgUsuario = e.getMessage();
            }
4

0 に答える 0