Java.sql.SQLException: ORA-01006: a variável de ligação não existe[RESOLVIDO]

4 respostas
R

Ta dando um erro de SQL estranho. Preciso de ajuda

log do erro:
...
...
[08/07/2008 02:19:21,609] INFO  [http-8080-2] (SessionFactoryObjectFactory.java:86) ### Factory name: session1 ###
[08/07/2008 02:19:21,656] INFO  [http-8080-2] (NamingHelper.java:26) ### JNDI InitialContext properties:{} ###
[08/07/2008 02:19:21,656] INFO  [http-8080-2] (SessionFactoryObjectFactory.java:91) ### Bound factory to JNDI name: session1 ###
[08/07/2008 02:19:21,656] WARN  [http-8080-2] (SessionFactoryObjectFactory.java:101) ### InitialContext did not implement EventContext ###
[08/07/2008 02:19:22,688] ERROR [http-8080-2] (ItemMaterialServicoDAO.java:208) ### java.sql.SQLException: ORA-01006: a variável de ligação não existe ###
o problema esta aqui:
public ArrayList<ItemMaterialServico> pesquisarMaterial(
            String dscMaterial, int codCategoria, int codGrupo, int codClasse) {
        String sql =
                new StringBuilder()
                    .append("SELECT                                                         ")
                    .append("   IMS.*                                                       ")
                    .append("FROM                                                           ")
                    .append("   ADM_GESTAOMATERIAL.VM_ITEM_MATERIAL_SERVICO_IMS IMS         ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_ITEM_MATERIAL_IMA IMA      ")
                    .append("       ON IMA.PK_SEQ_ITEM_MATERIAL_IMA = IMS.ID_IMS            ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_MATERIAL_MAT MAT           ")
                    .append("       ON IMA.FK_SEQ_MATERIAL_MAT = MAT.PK_SEQ_MATERIAL_MAT    ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_CLASSE_CLA CLA             ")
                    .append("       ON MAT.FK_SEQ_CLASSE_CLA = CLA.PK_SEQ_CLASSE_CLA        ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_GRUPO_GRU GRU              ")
                    .append("       ON CLA.FK_SEQ_GRUPO_GRU = GRU.PK_SEQ_GRUPO_GRU          ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_CATEGORIA_CAT CAT          ")
                    .append("       ON GRU.FK_SEQ_CATEGORIA_CAT = CAT.PK_SEQ_CATEGORIA_CAT  ")
                    .append("WHERE                                                          ")
                    .append("   UPPER(IMS.DSC_IMS) LIKE UPPER('%?%') AND                    ")
                    .append("   CAT.PK_SEQ_CATEGORIA_CAT = ?         AND                    ")
                    .append("   GRU.COD_GRUPO_GRU        = ?         AND                    ")
                    .append("   CLA.COD_CLASSE_CLA       = ?                                ")
                    .append("UNION                                                          ")
                    .append("SELECT                                                         ")
                    .append("   IMS.*                                                       ")
                    .append("FROM                                                           ")
                    .append("   ADM_GESTAOMATERIAL.VM_ITEM_MATERIAL_SERVICO_IMS IMS         ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_ITEM_SERVICO_ISE ISE       ")
                    .append("       ON ISE.PK_SEQ_ITEM_SERVICO_ISE = IMS.ID_IMS             ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_SERVICO_SER SER            ")
                    .append("       ON ISE.FK_SEQ_SERVICO_SER = SER.PK_SEQ_SERVICO_SER      ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_CLASSE_CLA CLA             ")
                    .append("       ON SER.FK_SEQ_CLASSE_CLA = CLA.PK_SEQ_CLASSE_CLA        ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_GRUPO_GRU GRU              ")
                    .append("       ON CLA.FK_SEQ_GRUPO_GRU = GRU.PK_SEQ_GRUPO_GRU          ")
                    .append("   INNER JOIN ADM_GESTAOMATERIAL.TB_CATEGORIA_CAT CAT          ")
                    .append("       ON GRU.FK_SEQ_CATEGORIA_CAT = CAT.PK_SEQ_CATEGORIA_CAT  ")
                    .append("WHERE                                                          ")
                    .append("   UPPER(IMS.DSC_IMS) LIKE UPPER('%?%') AND                    ")
                    .append("   CAT.PK_SEQ_CATEGORIA_CAT = ?         AND                    ")
                    .append("   GRU.COD_GRUPO_GRU        = ?         AND                    ")
                    .append("   CLA.COD_CLASSE_CLA       = ?                                ")
                    .toString();
                
        PreparedStatement stmt;
        Session session = HibernateUtil.currentSession();
        Transaction tx = session.beginTransaction();
        
        try {
            this.connection = session.connection();

            stmt = this.connection.prepareStatement(sql);

            stmt.setString(1, dscMaterial);
            stmt.setInt(2, codCategoria);
            stmt.setInt(3, codGrupo);
            stmt.setInt(4, codClasse);
            
            stmt.setString(5, dscMaterial);
            stmt.setInt(6, codCategoria);
            stmt.setInt(7, codGrupo);
            stmt.setInt(8, codClasse);
            
            ResultSet rs = (ResultSet) stmt.executeQuery();

            itemMaterialServicos = new ArrayList<ItemMaterialServico>();

            while (rs.next()) {
                ItemMaterialServico itemMaterialServico = new ItemMaterialServico();

                Integer idIms = rs.getInt("ID_IMS");
                Short codIms = rs.getShort("COD_IMS");
                String dscIms = rs.getString("DSC_IMS");
                String tipoIms = rs.getString("TIPO_IMS");
                String fornecimentoIms = rs.getString("FORNECIMENTO_IMS");

                itemMaterialServico.setIdItemMatSer(idIms);
                itemMaterialServico.setCodItemMatSer(codIms);
                itemMaterialServico.setDscItemMatSer(dscIms);
                itemMaterialServico.setTipoItemMatSer(tipoIms);
                itemMaterialServico.setFornecimentoItemMatSer(fornecimentoIms);

                itemMaterialServicos.add(itemMaterialServico);
            }
            rs.close();
            stmt.close();
            tx.commit();
        } catch (SQLException e) {
            tx.rollback();
            logger.error(e);
        } finally {
            if (this.connection != null) {
                this.connectionClosse();
            }
            HibernateUtil.closeSession();
        }
        return itemMaterialServicos;
    }

obs: acabei usando o prepare statement, porque o programa eh muito pequeno e acho que eh um desperdicio usar o hibernate ... to usando ele mesmo soh para fazer o pool de conexoes

o programa eh um pequeno web service que vai fornecer umas consultas no banco

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.ce.seplag.gestaoMaterial;

import br.gov.ce.seplag.gestaoMaterial.dao.CategoriaDAO;
import br.gov.ce.seplag.gestaoMaterial.dao.ClasseDAO;
import br.gov.ce.seplag.gestaoMaterial.dao.GrupoDAO;
import br.gov.ce.seplag.gestaoMaterial.dao.ItemMaterialServicoDAO;
import br.gov.ce.seplag.gestaoMaterial.model.Categoria;
import br.gov.ce.seplag.gestaoMaterial.model.Classe;
import br.gov.ce.seplag.gestaoMaterial.model.Grupo;
import br.gov.ce.seplag.gestaoMaterial.model.ItemMaterialServico;
import java.util.ArrayList;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author bernardo
 */
@WebService()
public class gestaoMaterialWs {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "listarCategorias")
    public ArrayList<Categoria> listarCategorias() {
        ArrayList<Categoria> categorias;
        CategoriaDAO catDAO = new CategoriaDAO();
        categorias = catDAO.listarCategorias();
        return categorias;
    }
    
    /**
     * Web service operation
     */
    @WebMethod(operationName = "listarGrupos")
    public ArrayList<Grupo> listarGrupos() {
        ArrayList<Grupo> grupos;
        GrupoDAO gruDAO = new GrupoDAO();
        grupos = gruDAO.listarGrupos();
        return grupos;
    }
    
    /**
     * Web service operation
     */
    @WebMethod(operationName = "listarClasses")
    public ArrayList<Classe> listarClasses() {
        ArrayList<Classe> classes;
        ClasseDAO gruDAO = new ClasseDAO();
        classes = gruDAO.listarClasses();
        return classes;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "pesquisarMaterial1")
    public ArrayList<ItemMaterialServico> pesquisarMaterial1(
            @WebParam(name = "codMaterial") int codMaterial,
            @WebParam(name = "codCategoria") int codCategoria) {
        ArrayList<ItemMaterialServico> ims;
        ItemMaterialServicoDAO imsDAO = new ItemMaterialServicoDAO();
        ims = imsDAO.pesquisarMaterial(codMaterial, codCategoria);
        return ims;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "pesquisarMaterial2")
    public ArrayList<ItemMaterialServico> pesquisarMaterial2(
            @WebParam(name = "parameter") String dscMaterial,
            @WebParam(name = "parameter1") int codCategoria,
            @WebParam(name = "parameter2") int codGrupo,
            @WebParam(name = "parameter3") int codClasse) {
        ArrayList<ItemMaterialServico> ims;
        ItemMaterialServicoDAO imsDAO = new ItemMaterialServicoDAO();
        ims = imsDAO.pesquisarMaterial(dscMaterial, codCategoria,codGrupo,codClasse);
        return ims;
    }
}
e a chamada do metodo no cliente
try { // Call Web Service Operation
            br.gov.ce.seplag.gestaomaterial.GestaoMaterialWsService service = new br.gov.ce.seplag.gestaomaterial.GestaoMaterialWsService();
            br.gov.ce.seplag.gestaomaterial.GestaoMaterialWs port = service.getGestaoMaterialWsPort();
            // TODO initialize WS operation arguments here
            java.lang.String parameter = "cop";
            int parameter1 = 9;
            int parameter2 = 75;
            int parameter3 = 50;
            // TODO process result here
            java.util.List<br.gov.ce.seplag.gestaomaterial.ItemMaterialServico> result = port.pesquisarMaterial2(parameter, parameter1, parameter2, parameter3);
            System.out.println("Result5 = " + result.size());
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }

**EDIT**
sim, quando eu tiro lah do SQL os ? e coloco os valores que eu to passando jah dentro do sql sem fazer 'stmt.set' .... ele funciona normal. to usando a ojdbc14.jar o banco eh oracle (logico :P)

4 Respostas

R

tipo assim, quando eu faco isso:

.append(" UPPER(IMS.DSC_IMS) LIKE UPPER('%" +dscMaterial+"%') AND ") .append(" CAT.PK_SEQ_CATEGORIA_CAT = " +codCategoria+" AND ") .append(" GRU.COD_GRUPO_GRU = " +codGrupo+" AND ") .append(" CLA.COD_CLASSE_CLA = " +codClasse)

funciona normal. -_-?

que pode ser isso?

Y

Tem como debugar a aplicação e capturar o comando SQL antes de ele ser executado para postar aqui?

[]´s

I

Tlz o problema seja as aspas que vc está colocando no código,

aqui ao invés de vc colocar as aspas e colocar o sinal de porcentagem coloque apenas a interrogação, não tenho certeza mais eu acho que o java coloca as aspas automaticamente.

.append("   UPPER(IMS.DSC_IMS) LIKE UPPER('%?%') AND                    ")

Certo:

.append("   UPPER(IMS.DSC_IMS) LIKE UPPER(?) AND                    ")

Coloque a o sinal de porcentagem no começo e no final da String dscMaterial.

R

ivo costa:
Tlz o problema seja as aspas que vc está colocando no código,

aqui ao invés de vc colocar as aspas e colocar o sinal de porcentagem coloque apenas a interrogação, não tenho certeza mais eu acho que o java coloca as aspas automaticamente.

.append("   UPPER(IMS.DSC_IMS) LIKE UPPER('%?%') AND                    ")

Certo:

.append("   UPPER(IMS.DSC_IMS) LIKE UPPER(?) AND                    ")

Coloque a o sinal de porcentagem no começo e no final da String dscMaterial.

era isso mesmo. vlw :wink:

Criado 8 de julho de 2008
Ultima resposta 8 de jul. de 2008
Respostas 4
Participantes 3