Error Connection Database; "relation does not exist"

Asked

Viewed 5,011 times

4

I am having Problem to Save Data from a Screen to my database I am getting the following error:

"org.postgresql.util.PSQL.Exception: ERROR: column "name" of relation "product registration" does not exist: 29"

heading 29 and the following:

pst = conex.com.prepareStatement("insert into cadastroproduto(nome, Preco_De_Custo,Preco_De_Venda,Marca,Categoria,Origem,Unidade_Medida) values(?,?,?,?,?,?,?)");

The Code I am using for the control that is giving error and the Following:

package controle;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import modelo.ModeloCadastroProduto;

public class ControleCadastroProduto {
ConexaoBD conex = new ConexaoBD();
ModeloCadastroProduto mod;

public class ControleCadastroProduto {
    ConexaoBD conex = new ConexaoBD();
    ModeloCadastroProduto mod;

    public ControleCadastroProduto() {
        this.mod = new ModeloCadastroProduto();
    }

    public void Salvar(ModeloCadastroProduto mod){
        conex.conexao();
        try {
            PreparedStatement pst;
            pst = conex.com.prepareStatement("insert into cadastroproduto(nome, Preco_De_Custo,Preco_De_Venda,Marca,Categoria,Origem,Unidade_Medida) values(?,?,?,?,?,?,?)");
            pst.setString(1,mod.getNome());
            pst.setDouble(2,mod.getPrecodecusto());
            pst.setDouble(3,mod.getPrecodevenda());
            pst.setString(4,mod.getMarca());
            pst.setString(5,mod.getCategoria());
            pst.setString(6,mod.getOrigem());
            pst.setString(7,mod.getUnidademedida());
            pst.execute();
            JOptionPane.showMessageDialog(null,"Dados Cadastrados com Sucesso!");
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,"Erro Ao Cadastrar\nErro: "+ex);
        }

        conex.desconecta();
    }
}

Table code:

CREATE TABLE public.cadastroproduto
(
    "ID_Produto" integer NOT NULL DEFAULT nextval('"CadastroProduto_ID_Produto_seq"'::regclass),
    "Nome" character(1) COLLATE pg_catalog."default" NOT NULL,
    "Preco_De_Custo" money NOT NULL,
    "Preco_De_Venda" money,
    "Marca" character varying(60) COLLATE pg_catalog."default",
    "Categoria" character varying(60) COLLATE pg_catalog."default",
    "Origem" character varying COLLATE pg_catalog."default",
    "Unidade_Medida" character varying COLLATE pg_catalog."default",
    CONSTRAINT "CadastroProduto_pkey" PRIMARY KEY ("ID_Produto")
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.cadastroproduto
    OWNER to postgres;
  • 1

    you checked if the column name nome is exactly like this in the table cadastroproduto in your bank?

  • is exactly the same.

  • In doubt puts in question the structure of the table

1 answer

0


column "name" of relation "product registration"

Names of identifiers (tables, field, etc.) with uppercase letters or special characters in Postgresql should be delimited with quotes, otherwise they will not be recognized.

Change:

insert into cadastroproduto(nome, Preco_De_Custo)

To: apply this to all fields that have uppercase letters.

pst = conex.com.prepareStatement("insert into cadastroproduto(nome, \"Preco_De_Custo\", \"Preco_De_Venda\", \"Marca\", \"Categoria\", \"Origem\",\"Unidade_Medida\") 

If possible it is better to change the names of the columns and leave everything in box, so avoid the leaks.

  • even with the quotation marks the error still persists.

  • @matheusferreira puts in question the create of the table, in pgAdmin also happens this error?

  • already put a create , not only when I save something, fill the fields and click the save button it performs the validation with the database connection and right after clicking ok it presents the error I specified at the beginning.

  • thanks to your reply I managed to solve the problem, well I made change in pgadmin of the uppercase letters and the characters and it worked, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.