Hello I have this part of code:
public void inserir(Assignatura as) throws GestorException {
//TODO codificar el metode inserir
String sentenciaSQL = null;
PreparedStatement elm = null;
try{
elm = con.prepareStatement(sentenciaSQL);
// elm = con.prepareStatement("INSERT INTO assignatura (codi, assignatura, dies");
sentenciaSQL = "INSERT INTO assignatura VALUES (1, "
+"'Mates','dilluns')";
elm.executeUpdate(sentenciaSQL);
//elm.setObject(1,as);
//elm.executeUpdate();
} catch (SQLException ex){
System.out.println("error!"+ex.getMessage());
System.out.println("SQLsState:"+ ex.getSQLState());
}finally{
try {
if(elm!=null && !elm.isClosed()){
elm.close();
}
} catch (SQLException ex) {/*llàstima!*/}
try {
if(con!=null && !con.isClosed()){
con.close();
}
} catch (SQLException ex) {
Logger.getLogger(GestorAssignatura.class.getName()).log(Level.SEVERE, null, ex);
}
}
I'm trying things but I don't know 100% how to do it... the sql is this:
CREATE TYPE dades_assignatura as (nom character varying(30), hores integer);
CREATE TABLE Assignatura
(
codi integer NOT NULL,
assignatura dades_assignatura,
dies character varying(9)[],
CONSTRAINT clauPrimariaAssignatura PRIMARY KEY (codi)
)
WITH (
OIDS=FALSE
);
ALTER TABLE Assignatura
OWNER TO postgres;
I'm going crazy... I don't know 100% how to do it and I can't find any information either :(
I see that your insert enters in the value 3 data, one of the integer type and two of the text type, but your database has fields of a different type than the insert you indicate.
This is an example for your table insert
INSERT INTO public.assignatura(codi, assignatura, dies)VALUES (1, '("lulu",1)', '{"lunes"}');
but I don't know if your last field should be an arraydies character varying(9)[],
or justdies character varying(9),