fare i todo
1: insert in table (continuare quello gia scritto) 2: i getVar in userdata (finirli)
This commit is contained in:
parent
5619d2dd8c
commit
4d21cb5bda
|
@ -17,4 +17,8 @@ public class Data implements Comparable<Data>{
|
|||
return this.mese - data.mese;
|
||||
return this.giorno - data.giorno;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return giorno + "-" + mese + "-" + anno;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class Main {
|
|||
+ "END $$;");
|
||||
stmt.execute();
|
||||
|
||||
Table anagraficaTable = new Table(connection, "CREATE TABLE IF NOT EXISTS anagrafica("
|
||||
Table anagrafica = new Table(connection, "anagrafica", "CREATE TABLE IF NOT EXISTS anagrafica("
|
||||
+ "codice_fiscale VARCHAR(16) PRIMARY KEY,"
|
||||
+ "nome VARCHAR(16) NOT NULL,"
|
||||
+ "cognome VARCHAR(16) NOT NULL,"
|
||||
|
@ -29,6 +29,11 @@ public class Main {
|
|||
+ "categorie_appartenenze categoria_appartenenza[],"
|
||||
+ "password VARCHAR(16)"
|
||||
+ ")");
|
||||
|
||||
UserData edi = new UserData("Edi", "DeCandido", "1234", new Data(20, 07, 2023), "Marte", "fethergay");
|
||||
System.out.println(edi);
|
||||
|
||||
anagrafica.insert(edi);
|
||||
|
||||
System.out.println("ok");
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@ import java.sql.SQLException;
|
|||
|
||||
public class Table {
|
||||
Connection connection;
|
||||
String name;
|
||||
|
||||
public Table(Connection connection, String statement) throws SQLException {
|
||||
public Table(Connection connection, String name, String statement) throws SQLException {
|
||||
this.connection = connection;
|
||||
|
||||
this.name = name;
|
||||
this.execute(statement);
|
||||
}
|
||||
|
||||
|
@ -14,4 +15,28 @@ public class Table {
|
|||
var stmt = connection.prepareStatement(statement);
|
||||
stmt.execute();
|
||||
}
|
||||
|
||||
|
||||
public void insert(UserData userdata) throws SQLException {
|
||||
var stmt = connection.prepareStatement("INSERT INTO anagrafica VALUES(codice_fiscale=?, nome=?, cognome=?, data_nascita=? luogo_nascita=?, categorie_appartenenza=?, password=?");
|
||||
|
||||
stmt.setString(1, userdata.getCodiceFiscale());
|
||||
stmt.setString(2, userdata.getNome());
|
||||
stmt.setString(3, userdata.getCogNome()); //TODO:
|
||||
stmt.setString(4, editedCustomer.email);
|
||||
stmt.setInt(5, editedCustomer.ID);
|
||||
|
||||
stmt.executeUpdate();
|
||||
|
||||
String stmt = "INSERT INTO " + name + " VALUES(" + userdata + ")";
|
||||
System.out.println(stmt);
|
||||
execute(stmt);
|
||||
}
|
||||
|
||||
//TODO: SELECT
|
||||
|
||||
//TODO: UPDATE
|
||||
|
||||
//TODO: DELETE
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class UserData {
|
||||
private final String codice_fiscale;
|
||||
private final String nome;
|
||||
private final String cognome;
|
||||
private final String codice_fiscale;
|
||||
private final Data data_nascita;
|
||||
private final String luogo_nascita;
|
||||
//TODO: non so farlo, List categoria_appartenenza = new ArrayList<>();
|
||||
|
@ -20,4 +20,29 @@ public class UserData {
|
|||
// this.categoria_apparteneza = categoria_appartenenza;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return codice_fiscale + ", "
|
||||
+ nome + ", "
|
||||
+ cognome + ", to_date('"
|
||||
+ data_nascita + "', 'dd-mm-yyyy'), "
|
||||
+ luogo_nascita + ", "
|
||||
+ password;
|
||||
}
|
||||
|
||||
public String getCodiceFiscale() {
|
||||
return codice_fiscale;
|
||||
}
|
||||
|
||||
public String getNome() {
|
||||
return nome;
|
||||
}
|
||||
|
||||
public String getCogNome() {
|
||||
return cognome;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return nome;
|
||||
} //TODO:
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue