Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.OutputStream;
- import java.net.Socket;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.Label;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- public class myClient extends Application{
- String responsoCredenziali;
- String metodo;
- String comboSogg;
- String comboClass;
- String daServerSogg;
- String daServerClasse;
- String richiesta;
- InputStream iStream;
- OutputStream oStream;
- ObjectInputStream sIn;
- ObjectOutputStream sOut;
- //Login
- Label lUser = new Label(" Username");
- TextField tUser = new TextField();
- Label lPass = new Label(" Password");
- PasswordField tPass = new PasswordField();
- Button bLogin = new Button(" Login");
- //Registrazione
- Label lIdStud = new Label("Inserisci l'username");
- TextField tIdStud = new TextField();
- Label lPassStud = new Label("Inserisci la password");
- PasswordField tPassStud = new PasswordField();
- Label lNome = new Label(" Nome");
- TextField tNome = new TextField();
- Label lCognome = new Label(" Cognome");
- TextField tCognome = new TextField();
- Label lData = new Label(" Data di nascita");
- TextField tData = new TextField();
- Label lSesso = new Label (" Sesso");
- TextField tSesso = new TextField();
- Button btnRegistrati = new Button(" Non sei resgistrato?");
- Button btnIscrivi = new Button (" Registrati");
- Label lblLog = new Label(" Log");
- TextArea txtLog = new TextArea();
- Button btnConfReg = new Button("Conferma registrazione");
- // Inserimento e modifica soggeto
- Label lNom = new Label ("Nome Azienda");
- TextField tNom = new TextField();
- Label lVia = new Label ("Via Azienda");
- TextField tVia = new TextField();
- Label lCiv = new Label ("Civico Azienda");
- TextField tCiv = new TextField();
- Label lCap = new Label ("CAP Azienda");
- TextField tCap = new TextField();
- Label lCitta = new Label ("Via Azienda");
- TextField tCitta = new TextField();
- Label lCod = new Label ("Codice Fiscale Azienda");
- TextField tCod = new TextField();
- Label lPiva = new Label ("Partita Iva Azienda");
- TextField tPiva = new TextField();
- Label lNomRap = new Label ("Nome Rappresentante");
- TextField tNomRap = new TextField();
- Label lCognRap = new Label ("Cognome Rappresentante");
- TextField tCognRap = new TextField();
- Label lCfRap = new Label ("Codice Fiscale Rappresentante");
- TextField tCfRap = new TextField();
- Label lIdAtt = new Label ("Seleziona il soggetto da modificare");
- TextField tIdAtt = new TextField();
- ComboBox cIdAtt = new ComboBox();
- ComboBox cRichieste = new ComboBox();
- Label lRichieste = new Label("Registrazioni");
- Button bInsSogg = new Button("Inserisci dati");
- Button bModSogg = new Button ("Modifica dati");
- Button bLogout = new Button("Logout");
- //inserimento classe
- Label lIdClasse = new Label ("iDClasse");
- ComboBox cIdClasse = new ComboBox();
- Label lAnno = new Label ("Anno");
- TextField tAnno = new TextField ();
- Label lNumero = new Label ("Numero");
- TextField tNumero = new TextField();
- Label lSezione = new Label ("Sezione");
- TextField tSezione = new TextField();
- Button bInsClasse = new Button ("Inserisci classe");
- Button bModClasse = new Button("Modifica classe");
- GridPane p = new GridPane();
- private Socket soc;
- public void start(Stage f){
- bLogin.setOnAction(e -> Login());
- btnRegistrati.setOnAction(e -> registrati());
- btnIscrivi.setOnAction(e -> Iscrivi());
- btnConfReg.setOnAction(e -> confReg());
- lIdStud.setVisible(false);
- tIdStud.setVisible(false);
- lPassStud.setVisible(false);
- tPassStud.setVisible(false);
- lNome.setVisible(false);
- tNome.setVisible(false);
- lCognome.setVisible(false);
- tCognome.setVisible(false);
- lData.setVisible(false);
- tData.setVisible(false);
- lSesso.setVisible(false);
- tSesso.setVisible(false);
- btnIscrivi.setVisible(false);
- p.setPadding(new Insets(10,10,10,10));
- p.setHgap(10);
- p.setVgap(10);
- p.add(btnRegistrati, 0, 0);
- p.add(lUser, 0, 1);
- p.add(tUser, 1, 1);
- p.add(bLogin, 2, 1);
- p.add(lPass, 0, 2);
- p.add(tPass, 1, 2);
- p.add(lIdStud, 0, 4);
- p.add(tIdStud, 1, 4);
- p.add(lPassStud, 0, 5);
- p.add(tPassStud, 1, 5);
- p.add(lNome, 0, 6);
- p.add(tNome, 1, 6);
- p.add(lCognome, 2, 4);
- p.add(tCognome, 3, 4);
- p.add(lData, 2, 5);
- p.add(tData, 3, 5);
- p.add(lSesso, 2, 6);
- p.add(tSesso, 3, 6);
- p.add(btnIscrivi, 2, 8);
- p.add(lblLog, 0, 10);
- p.add(txtLog, 1, 10, 3, 1);
- Scene s = new Scene(p, 650, 600);
- f.setScene(s);
- f.show();
- }
- public void registrati() {
- lIdStud.setVisible(true);
- tIdStud.setVisible(true);
- lPassStud.setVisible(true);
- tPassStud.setVisible(true);
- lNome.setVisible(true);
- tNome.setVisible(true);
- lCognome.setVisible(true);
- tCognome.setVisible(true);
- lData.setVisible(true);
- tData.setVisible(true);
- lSesso.setVisible(true);
- tSesso.setVisible(true);
- bLogin.setVisible(false);
- lUser.setVisible(false);
- lPass.setVisible(false);
- tUser.setVisible(false);
- tPass.setVisible(false);
- btnIscrivi.setVisible(true);
- }
- public void confReg() {
- String richieste;
- richieste = cRichieste.getValue().toString();
- String conferma = tIdStud.getText() + " " + tPassStud.getText()+ " " + tNome.getText() + " " + tCognome.getText()+ " " + tData.getText() + " " + tSesso.getText();
- String [] confSplit = conferma.split(" ");
- if (richieste.equals(confSplit[2] + " " + confSplit[3])) {
- try {
- metodo = "confRegistrazione";
- sOut.writeObject(metodo);
- sOut.flush();
- String insert = "INSERT INTO studente (idStudente,password,nome,cognome,dataNascita,sesso) VALUES('"+confSplit[0]+"','"+confSplit[1]+"','"+confSplit[2]+"','"+confSplit[3]+"','"+confSplit[4]+"','"+confSplit[5] + "')";
- sOut.writeObject(insert);
- sOut.flush();
- daServerClasse = (String) sIn.readObject();
- cIdClasse.getItems().add(daServerClasse);
- daServerClasse = (String) sIn.readObject();
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e);
- ScriviLog(e.toString());
- }
- }
- }
- public void Iscrivi() {
- bLogin.setVisible(true);
- lUser.setVisible(true);
- lPass.setVisible(true);
- tUser.setVisible(true);
- tPass.setVisible(true);
- richiesta = tNome.getText() + " " + tCognome.getText();
- cRichieste.getItems().add(richiesta);
- }
- public void Login(){
- if(tUser.getText().equals("") || tPass.getText().equals("") ){
- ScriviLog("Compilare entrambi i campi");
- }else{
- try{
- ScriviLog("Connessione al Server in corso...");
- soc = new Socket("localhost", 12345);
- ScriviLog("Connessione Avvenuta");
- oStream = soc.getOutputStream();
- iStream = soc.getInputStream();
- sOut = new ObjectOutputStream (oStream);
- sIn = new ObjectInputStream(iStream);
- sOut.writeObject(tUser.getText());
- sOut.flush();
- sOut.writeObject(tPass.getText());
- sOut.flush();
- responsoCredenziali = (String)sIn.readObject();
- if(responsoCredenziali.equals("stud")){
- ScriviLog("Benvenuto");
- p.getChildren().clear();
- Label lOre = new Label("Ore Alternanza");
- TextField tOre = new TextField();
- Label lDescAtt = new Label("Descrivi brevemente l'attività");
- TextArea tDescAtt = new TextArea();
- Label lUt = new Label("Inserisci l'username");
- TextField tUt = new TextField();
- Label lData = new Label("Data Alternanza");
- TextField tData = new TextField();
- Button bRichiedi = new Button("Conferma");
- Button bLogout = new Button("Logout");
- bRichiedi.setOnAction(e -> RichiediOre());
- bLogout.setOnAction(e -> LogoutStud());
- p.setPadding(new Insets(10,10,10,10));
- p.setHgap(10);
- p.setVgap(10);
- p.add(lOre, 0, 0);
- p.add(tOre, 1, 0);
- p.add(lDescAtt, 0, 1);
- p.add(tDescAtt, 1, 1, 3, 1);
- p.add(lUt, 0, 2);
- p.add(tUt, 1, 2);
- p.add(lData, 0, 3);
- p.add(tData, 1, 3);
- p.add(bRichiedi, 1, 4);
- p.add(bLogout, 1, 5);
- }else{
- ScriviLog("Non sei uno studente");
- }
- if(responsoCredenziali.equals("amm")){
- ScriviLog("Benvenuto");
- p.getChildren().clear();
- bModSogg.setOnAction(e -> modSogg());
- bInsSogg.setOnAction(e -> insSogg());
- bInsClasse.setOnAction(e -> insClasse());
- bModClasse.setOnAction(e -> modClasse());
- bLogout.setOnAction(e -> LogoutAdmin());
- p.add(lNom, 0, 0);
- p.add(tNom, 1, 0);
- p.add(lVia, 0, 1);
- p.add(tVia, 1, 1);
- p.add(lCiv, 0, 2);
- p.add(tCiv, 1, 2);
- p.add(lCap, 0, 3);
- p.add(tCap, 1, 3);
- p.add(lCitta, 0, 4);
- p.add(tCitta, 1, 4);
- p.add(lCod, 0, 5);
- p.add(tCod, 1, 5);
- p.add(lPiva, 0, 6);
- p.add(tPiva, 1, 6);
- p.add(lNomRap, 0, 7);
- p.add(tNomRap, 1, 7);
- p.add(lCognRap, 0, 8);
- p.add(tCognRap, 1, 8);
- p.add(lCfRap, 0, 9);
- p.add(tCfRap, 1, 9);
- p.add(lIdAtt, 0, 10);
- p.add(cIdAtt, 1, 10, 2, 1);
- p.add(bInsSogg, 1, 12);
- p.add(bModSogg, 1, 13);
- p.add(bLogout, 1, 14);
- p.add(lIdClasse, 2, 0);
- p.add(cIdClasse, 3, 0);
- p.add(lAnno, 2, 1);
- p.add(tAnno, 3, 1);
- p.add(lNumero, 2, 2);
- p.add(tNumero, 3, 2);
- p.add(lSezione, 2, 3);
- p.add(tSezione, 3, 3);
- p.add(bInsClasse, 3, 4);
- p.add(bModClasse, 3, 5);
- p.add(btnConfReg, 3, 7);
- p.add(lRichieste, 2, 6);
- p.add(cRichieste, 3, 6);
- try {
- metodo = "comboSogg";
- sOut.writeObject(metodo);
- sOut.flush();
- sOut.writeObject("SELECT idSoggetto FROM soggetto");
- sOut.flush();
- sOut.writeObject("SELECT Nominativo FROM soggetto");
- sOut.flush();
- daServerSogg = (String) sIn.readObject();
- while(daServerSogg!=null) {
- cIdAtt.getItems().add(daServerSogg);
- daServerSogg = (String) sIn.readObject();
- }
- }catch(IOException e) {
- }
- try {
- metodo = "comboClasse";
- sOut.writeObject(metodo);
- sOut.flush();
- sOut.writeObject("SELECT idClasse,anno,numero,sezione FROM classe");
- sOut.flush();
- daServerClasse = (String) sIn.readObject();
- while(daServerClasse!=null) {
- cIdClasse.getItems().add(daServerClasse);
- daServerClasse = (String) sIn.readObject();
- }
- }catch(IOException e) {
- }
- }else{
- ScriviLog("Non sei un Amministratore");
- }
- if(responsoCredenziali.equals("Errore")){
- ScriviLog("Credenziali errate");
- }
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e);
- ScriviLog(e.toString());
- }
- }
- }
- public void RichiediOre() {
- p.getChildren().clear();
- Label lAttesa = new Label ("In attesa di conferma");
- p.add(lAttesa, 0, 0);
- }
- //Metodo per inserire dati soggetto
- public void insSogg() {
- metodo = "insSoggetto";
- try {
- sOut.writeObject(metodo);
- sOut.flush();
- sOut.writeObject(tNom.getText());
- sOut.flush();
- sOut.writeObject(tVia.getText());
- sOut.flush();
- sOut.writeObject(tCiv.getText());
- sOut.flush();
- sOut.writeObject(tCap.getText());
- sOut.flush();
- sOut.writeObject(tCitta.getText());
- sOut.flush();
- sOut.writeObject(tCod.getText());
- sOut.flush();
- sOut.writeObject(tPiva.getText());
- sOut.flush();
- sOut.writeObject(tNomRap.getText());
- sOut.flush();
- sOut.writeObject(tCognRap.getText());
- sOut.flush();
- sOut.writeObject(tCfRap.getText());
- sOut.flush();
- System.out.println("Query riuscita con successo!");
- }catch(IOException e) {
- System.out.println(e);
- }
- }
- public void modSogg() {
- //metodo modifica dati
- metodo = "modificaSoggetto";
- try{
- sOut.writeObject(metodo);
- sOut.flush();
- sOut.writeObject(tNom.getText());
- sOut.flush();
- sOut.writeObject(tVia.getText());
- sOut.flush();
- sOut.writeObject(tCiv.getText());
- sOut.flush();
- sOut.writeObject(tCap.getText());
- sOut.flush();
- sOut.writeObject(tCitta.getText());
- sOut.flush();
- sOut.writeObject(tCod.getText());
- sOut.flush();
- sOut.writeObject(tPiva.getText());
- sOut.flush();
- sOut.writeObject(tNomRap.getText());
- sOut.flush();
- sOut.writeObject(tCognRap.getText());
- sOut.flush();
- sOut.writeObject(tCfRap.getText());
- sOut.flush();
- comboSogg = cIdAtt.getValue().toString();
- String[] split = comboSogg.split("-");
- sOut.writeObject(split[0]);
- sOut.flush();
- System.out.println("Modifica riuscita con successo!");
- }catch(IOException e){
- System.out.println(e);
- ScriviLog(e.toString());
- }
- }
- public void insClasse() {
- metodo = "inserisciClasse";
- try {
- sOut.writeObject(metodo);
- sOut.flush();
- sOut.writeObject(tAnno.getText());
- sOut.flush();
- sOut.writeObject(tNumero.getText());
- sOut.flush();
- sOut.writeObject(tSezione.getText());
- System.out.println("Query classe riuscita con successo!");
- }catch(IOException e) {
- System.out.println(e);
- }
- }
- public void modClasse() {
- //metodo modifica classe
- metodo = "modificaClasse";
- try{
- sOut.writeObject(metodo);
- sOut.flush();
- comboClass = cIdClasse.getValue().toString();
- String[] split1 = comboClass.split("-");
- sOut.writeObject(split1[0]);
- sOut.flush();
- sOut.writeObject(tAnno.getText());
- sOut.flush();
- sOut.writeObject(tNumero.getText());
- sOut.flush();
- sOut.writeObject(tSezione.getText());
- sOut.flush();
- System.out.println("Modifica classe con successo!");
- }catch(IOException e){
- System.out.println(e);
- ScriviLog(e.toString());
- }
- }
- public void LogoutAdmin() {
- p.getChildren().clear();
- Label lUser = new Label(" Username");
- TextField tUser = new TextField();
- Label lPass = new Label(" Password");
- PasswordField tPass = new PasswordField();
- Button bLogin = new Button(" Login");
- Label lNome = new Label(" Nome");
- TextField tNome = new TextField();
- Label lCognome = new Label(" Cognome");
- TextField tCognome = new TextField();
- Label lData = new Label(" Data di nascita");
- TextField tData = new TextField();
- Label lSesso = new Label (" Sesso");
- TextField tSesso = new TextField();
- Button btnRegistrati = new Button(" Non sei resgistrato?");
- Button btnIscrivi = new Button (" Registrati");
- Label lblLog = new Label(" Log");
- TextArea txtLog = new TextArea();
- bLogin.setOnAction(e -> Login());
- btnRegistrati.setOnAction(e -> registrati());
- lNome.setVisible(false);
- tNome.setVisible(false);
- lCognome.setVisible(false);
- tCognome.setVisible(false);
- lData.setVisible(false);
- tData.setVisible(false);
- lSesso.setVisible(false);
- tSesso.setVisible(false);
- btnIscrivi.setVisible(false);
- p.setPadding(new Insets(10,10,10,10));
- p.setHgap(10);
- p.setVgap(10);
- p.add(btnRegistrati, 0, 0);
- p.add(lUser, 0, 1);
- p.add(tUser, 1, 1);
- p.add(bLogin, 2, 1);
- p.add(lPass, 0, 2);
- p.add(tPass, 1, 2);
- p.add(lNome, 0, 4);
- p.add(tNome, 1, 4);
- p.add(lCognome, 0, 5);
- p.add(tCognome, 1, 5);
- p.add(lData, 0, 6);
- p.add(tData, 1, 6);
- p.add(lSesso, 0, 7);
- p.add(tSesso, 1, 7);
- p.add(btnIscrivi, 1, 8);
- p.add(lblLog, 0, 10);
- p.add(txtLog, 1, 10, 3, 1);
- }
- public void LogoutStud() {
- p.getChildren().clear();
- Label lUser = new Label(" Username");
- TextField tUser = new TextField();
- Label lPass = new Label(" Password");
- PasswordField tPass = new PasswordField();
- Button bLogin = new Button(" Login");
- Label lNome = new Label(" Nome");
- TextField tNome = new TextField();
- Label lCognome = new Label(" Cognome");
- TextField tCognome = new TextField();
- Label lData = new Label(" Data di nascita");
- TextField tData = new TextField();
- Label lSesso = new Label (" Sesso");
- TextField tSesso = new TextField();
- Button btnRegistrati = new Button(" Non sei resgistrato?");
- Button btnIscrivi = new Button (" Registrati");
- Label lblLog = new Label(" Log");
- TextArea txtLog = new TextArea();
- bLogin.setOnAction(e -> Login());
- btnRegistrati.setOnAction(e -> registrati());
- lNome.setVisible(false);
- tNome.setVisible(false);
- lCognome.setVisible(false);
- tCognome.setVisible(false);
- lData.setVisible(false);
- tData.setVisible(false);
- lSesso.setVisible(false);
- tSesso.setVisible(false);
- btnIscrivi.setVisible(false);
- p.setPadding(new Insets(10,10,10,10));
- p.setHgap(10);
- p.setVgap(10);
- p.add(btnRegistrati, 0, 0);
- p.add(lUser, 0, 1);
- p.add(tUser, 1, 1);
- p.add(bLogin, 2, 1);
- p.add(lPass, 0, 2);
- p.add(tPass, 1, 2);
- p.add(lNome, 0, 4);
- p.add(tNome, 1, 4);
- p.add(lCognome, 0, 5);
- p.add(tCognome, 1, 5);
- p.add(lData, 0, 6);
- p.add(tData, 1, 6);
- p.add(lSesso, 0, 7);
- p.add(tSesso, 1, 7);
- p.add(btnIscrivi, 1, 8);
- p.add(lblLog, 0, 10);
- p.add(txtLog, 1, 10, 3, 1);
- }
- public static void main (String[]args) {
- launch(args);
- }
- private void ScriviLog(String s) {
- txtLog.setText(txtLog.getText() + s + "\n");
- txtLog.setScrollTop(Double.MAX_VALUE);
- }
- }
- import java.sql.*;
- import java.io.IOException;
- import java.net.Socket;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- public class ServerThread extends Thread{
- Socket soc;
- InputStream iStream;
- OutputStream oStream;
- ObjectInputStream sIn;
- ObjectOutputStream sOut;
- String idSogg;
- String Nom;
- String idClas;
- String annoClasse;
- String numClas;
- String sezClas;
- String registrazione;
- //variabili login
- String userId;
- String password;
- //variabili soggetto
- String nominativo;
- String via;
- String civico;
- String CAP;
- String citta;
- String codiceFiscale;
- String partitaIva;
- String nomeRapp;
- String cognomeRapp;
- String cfRapp;
- int idAttività;
- //variabili classe
- int idClasse;
- int anno;
- int numero;
- String sezione;
- String metodo;
- String combo;
- public ServerThread(Socket s){
- soc = s;
- }
- public void run(){
- // apertura canale di comunicazione
- System.out.println(getName() + ": apertura canale di comunicazione...");
- try{
- iStream = soc.getInputStream();
- oStream = soc.getOutputStream();
- sIn = new ObjectInputStream(iStream);
- sOut = new ObjectOutputStream(oStream);
- System.out.println(getName()+ ": ...canale di comunicazione aperto.");
- // legge username e password
- userId = (String)sIn.readObject();
- password = (String)sIn.readObject();
- System.out.println(getName() + ": Ricevute credenziali di accesso.");
- // controlliamo le credenziali
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Caricamento Diver");
- }catch(ClassNotFoundException e) {
- }
- String url = "jdbc:mysql://localhost:3306?/scrum?user=root&password=";
- System.out.println("Connessione al database in corso...");
- try (Connection connection = DriverManager.getConnection(url)) {
- System.out.println("Database connesso!");
- Statement stm = connection.createStatement();
- //controllo credenziali
- ResultSet rs = stm.executeQuery("SELECT idStudente, password FROM studente");
- while (rs.next()) {
- if(rs.getString("idStudente").equals(userId) && rs.getString("password").equals(password)) {
- System.out.println("Benvenuto " + userId);
- sOut.writeObject("stud");
- sOut.flush();
- }
- }
- connection.close();
- }catch(SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- ResultSet rs = stm.executeQuery("SELECT idAmministratore, password FROM amministratore");
- while (rs.next()) {
- if(rs.getString("idAmministratore").equals(userId) && rs.getString("password").equals(password)) {
- System.out.println("Benvenuto " + userId);
- sOut.writeObject("amm");
- sOut.flush();
- }else {
- sOut.writeObject("errore");
- }
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- while(true) {
- metodo = (String)sIn.readObject();
- //Inserimento soggetto
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- if(metodo.equals("insSoggetto")) {
- nominativo = (String)sIn.readObject();
- via = (String)sIn.readObject();
- civico = (String)sIn.readObject();
- CAP = (String)sIn.readObject();
- citta = (String)sIn.readObject();
- codiceFiscale = (String)sIn.readObject();
- partitaIva = (String)sIn.readObject();
- nomeRapp = (String)sIn.readObject();
- cognomeRapp = (String)sIn.readObject();
- cfRapp = (String)sIn.readObject();
- stm.executeUpdate("INSERT INTO soggetto (Nominativo,via,civico,CAP,città,codiceFiscale,partitaIva,nomeRapp,cognomeRapp,cfRapp) VALUES('"+nominativo+"','"+via+"','"+civico+"','"+CAP+"','"+citta+"','"+codiceFiscale+"','"+partitaIva+"','"+nomeRapp+"','"+cognomeRapp+"','"+cfRapp+"')");
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- if(metodo.equals("confRegistrazione")) {
- registrazione = (String)sIn.readObject();
- stm.executeUpdate(registrazione);
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- //Popolamento combobox Soggetto
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- Statement stm1 = connection.createStatement();
- if(metodo.equals("comboSogg")) {
- idSogg = (String)sIn.readObject();
- Nom = (String)sIn.readObject();
- ResultSet rs = stm.executeQuery(idSogg);
- ResultSet rs1 = stm1.executeQuery(Nom);
- while (rs.next() && rs1.next()) {
- sOut.writeObject(rs.getString("idSoggetto") + "-" + rs1.getString("Nominativo"));
- sOut.flush();
- }
- sOut.writeObject(null);
- sOut.flush();
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- //Popolamento combobox Classe
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- if(metodo.equals("comboClasse")) {
- idClas = (String)sIn.readObject();
- ResultSet rs = stm.executeQuery(idClas);
- while (rs.next()) {
- sOut.writeObject(rs.getString("idClasse") + "-" + rs.getString("anno")+ "-" + rs.getString("numero")+ "-" + rs.getString("sezione"));
- sOut.flush();
- }
- sOut.writeObject(null);
- sOut.flush();
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- // Query modifica dati soggetto
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- if(metodo.equals("modificaSoggetto")) {
- nominativo = (String)sIn.readObject();
- via = (String)sIn.readObject();
- civico = (String)sIn.readObject();
- CAP = (String)sIn.readObject();
- citta = (String)sIn.readObject();
- codiceFiscale = (String)sIn.readObject();
- partitaIva = (String)sIn.readObject();
- nomeRapp = (String)sIn.readObject();
- cognomeRapp = (String)sIn.readObject();
- cfRapp = (String)sIn.readObject();
- idAttività =Integer.parseInt((String) sIn.readObject());
- stm.executeUpdate("UPDATE soggetto SET Nominativo = '"+nominativo+"',via = '"+via+"', civico = '"+civico+"',CAP = '"+CAP+"',città = '"+citta+"',codiceFiscale = '"+codiceFiscale+"',partitaIva = '"+partitaIva+"',nomeRapp = '"+nomeRapp+"',cognomeRapp = '"+cognomeRapp+"',cfRapp = '"+cfRapp+"' where idSoggetto = "+idAttività);
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- //Query inserisci dati classe
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- if(metodo.equals("inserisciClasse")) {
- anno = Integer.parseInt((String) sIn.readObject());
- numero = Integer.parseInt((String) sIn.readObject());
- sezione = (String)sIn.readObject();
- stm.executeUpdate("INSERT INTO classe (anno,numero,sezione) values("+anno+","+numero+",'"+sezione+"')");
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- // Query modifica dati classe
- try (Connection connection = DriverManager.getConnection(url)) {
- Statement stm = connection.createStatement();
- if(metodo.equals("modificaClasse")) {
- idClasse = Integer.parseInt((String) sIn.readObject());
- anno = Integer.parseInt((String) sIn.readObject());
- numero = Integer.parseInt((String) sIn.readObject());
- sezione = (String)sIn.readObject();
- stm.executeUpdate("UPDATE classe SET anno = "+anno+",numero = "+numero+", sezione = '"+sezione+"' where idClasse = "+idClasse);
- }
- connection.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Impossibile connettersi al database!", e);
- }
- }
- } catch(IOException | ClassNotFoundException e){
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement