Bom dia, Pessoal! Tudo bem?
Tenho uma classe pai Pessoa com dados gerais e 3 classes filhas, Administrador, Cliente e Vendedor
Comecei a implementar o banco de dados para a classe Adminitrador
Porém me esbarrei na hora de passar os dados pelo preparedstatement visto que só consigo acessar os métodos gets e sets referente aos dados da própria classe, não consigo enviar os atributos vindo pelo super
package MODEL;
/** ESCRITSQ BY: IAN S.A SANTOS */
public class Pessoaics {
public int id_pes;
public String nomepess;
public String celpess;
public String telpes;
public String logradouropess;
public String numlogpess;
public String bairropess;
public String cepess;
public int id_pesscity;
public int id_pessestciv;
public int id_pessgen;
public Pessoaics (int id_pes, String nomepess, String celpess,
String telpes, String logradouropess, String numlogpess,
String bairropess, String cepess, int id_pesscity,
int id_pessestciv, int id_pessgen){
this.id_pes = id_pes;
this.nomepess = nomepess;
this.celpess = celpess;
this.telpes = telpes;
this.logradouropess = logradouropess;
this.numlogpess = numlogpess;
this.bairropess = bairropess;
this.cepess = cepess;
this.id_pesscity = id_pesscity;
this.id_pessestciv = id_pessestciv;
this.id_pessgen = id_pessgen;
}
}
package MODEL;
/** ESCRITSQ BY: IAN S. A. SANTOS */
public class Admics extends Pessoaics {
private int id_adm;
private String logadm;
private String senhadm;
public Admics(int id_pes, String nomepess, String celpess, String telpes, String logradouropess, String numlogpess, String bairropess, String cepess, int id_pesscity, int id_pessestciv, int id_pessgen, int id_adm, String logadm, String senhadm) {
super(id_pes, nomepess, celpess, telpes, logradouropess, numlogpess, bairropess, cepess, id_pesscity, id_pessestciv, id_pessgen);
this.id_adm = id_adm;
this.logadm = logadm;
this.senhadm = senhadm;
this.id_pes = id_pes;
}
/**
* @return the id_adm
*/
public int getId_adm() {
return id_adm;
}
/**
* @param id_adm the id_adm to set
*/
public void setId_adm(int id_adm) {
this.id_adm = id_adm;
}
/**
* @return the logadm
*/
public String getLogadm() {
return logadm;
}
/**
* @param logadm the logadm to set
*/
public void setLogadm(String logadm) {
this.logadm = logadm;
}
/**
* @return the senhadm
*/
public String getSenhadm() {
return senhadm;
}
/**
* @param senhadm the senhadm to set
*/
public void setSenhadm(String senhadm) {
this.senhadm = senhadm;
}
}
package CONTROL;
/** ESCRITSQ BY: IAN S. A. SANTOS */
import FORMS.*;
import DATABASE.*;
import MODEL.*;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class ControlAdm {
ConectBD conectadm = new ConectBD();
public void InserirAdm (Admics modadm){
//JOptionPane.showMessageDialog(null, modusu.getNome_usu());
conectadm.conecta();
try{
PreparedStatement pst = conectadm.conn.prepareStatement("insert into Admics (nomepes, celpes, telpes, logradouropes, numlogpres, bairropres, cepes, id_pescity, id_pesest, id_pesgen, loginadm, senhadm)values(?,?,?,?,?,?,?,?,?,?,?,?)");
/*nomepes, celpes, telpes,
logradouropes, numlogpres,
bairropres, cepes, id_pescity,
id_pesest, id_pesgen,
loginadm, senhadm*/
pst.setString(1,modadm.(***COMO PASSAR OS DADOS SUPER AQUI, SÓ CONSIGO CHAMAR OS MÉTODOS GET DE ID_ADM, LOGINADM E SENHADM*** ());
pst.setString(2,modadm.());
pst.setString(3,modadm.());
pst.setInt(4,modadm.t());
pst.setInt(5,modadm.());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Dados do usuário: "+modadm.get()+" armazenados com sucesso!");
}catch(SQLException ex){
JOptionPane.showMessageDialog(null, "Erro ao cadastrar usuario:" + ex);
}
conectadm.desconecta();
}
}.
CREATE TABLE IF NOT EXISTS public."Pessoaics"
(
id_pes integer NOT NULL DEFAULT nextval('"Pessoaics_id_pes_seq"'::regclass),
nomepes character varying(30) COLLATE pg_catalog."default" NOT NULL,
celpes character varying(15) COLLATE pg_catalog."default" NOT NULL,
telpes character varying(15) COLLATE pg_catalog."default",
logradouropes character varying(30) COLLATE pg_catalog."default",
numlogpes character varying(4) COLLATE pg_catalog."default",
bairropes character varying(15) COLLATE pg_catalog."default",
cepes character varying(15) COLLATE pg_catalog."default",
id_pescity integer NOT NULL,
id_pesest integer,
id_pesgen integer,
CONSTRAINT pk_pes PRIMARY KEY (id_pescity, nomepes, celpes),
CONSTRAINT fk_pescity FOREIGN KEY (id_pescity)
REFERENCES public."Cityics" (id_city) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT fk_pesest FOREIGN KEY (id_pesest)
REFERENCES public."Estadocivilisc" (id_estciv) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT fk_pesgen FOREIGN KEY (id_pesgen)
REFERENCES public."Generoics" (id_gen) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
)
CREATE TABLE IF NOT EXISTS public.admics
(
-- Inherited from table public."Pessoaics": id_pes integer NOT NULL DEFAULT nextval('"Pessoaics_id_pes_seq"'::regclass),
-- Inherited from table public."Pessoaics": nomepes character varying(30) COLLATE pg_catalog."default" NOT NULL,
-- Inherited from table public."Pessoaics": celpes character varying(15) COLLATE pg_catalog."default" NOT NULL,
-- Inherited from table public."Pessoaics": telpes character varying(15) COLLATE pg_catalog."default",
-- Inherited from table public."Pessoaics": logradouropes character varying(30) COLLATE pg_catalog."default",
-- Inherited from table public."Pessoaics": numlogpes character varying(4) COLLATE pg_catalog."default",
-- Inherited from table public."Pessoaics": bairropes character varying(15) COLLATE pg_catalog."default",
-- Inherited from table public."Pessoaics": cepes character varying(15) COLLATE pg_catalog."default",
-- Inherited from table public."Pessoaics": id_pescity integer,
-- Inherited from table public."Pessoaics": id_pesest integer,
-- Inherited from table public."Pessoaics": id_pesgen integer,
id_adm integer,
loginadm character varying COLLATE pg_catalog."default",
senhadm character varying COLLATE pg_catalog."default"
)
INHERITS (public."Pessoaics")
TABLESPACE pg_default;