Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- // Mi connetto al database
- Connection conn = DriverManager.getConnection(connectionString, "carlocabras", "0");
- // Preparo la query con cui ricerco tutti i clienti e filtro per usr e psw
- String queryRicerca = "select * from cliente where " + "username = ? and password = ?";
- PreparedStatement stmt = conn.prepareStatement(queryRicerca);
- // Setto le due stringhe ? dello statement con i valori passati al metodo
- stmt.setString(1, usr);
- stmt.setString(2, psw);
- // Mando in esecuzione la query
- ResultSet res = stmt.executeQuery();
- //-----------------------------------------------------------------------------------------------
- // PROVA INSERIMENTO--------------------------------------------------------------------------
- stmt = conn.prepareStatement("INSERT INTO cliente (id, nome, cognome, codice_fiscale, data_nascita, saldo, username, password) " +
- "VALUES (default, 'Prova', 'prova', 'CBRCRL93S26V234A','1993-11-26',1000,'provaprova','0')");
- ResultSet rs = stmt.executeQuery(); //NOTARE CHE rs E NON res
- // In set ci deve essere un solo elemento (cliente) associato a quell'username e password. Mi assicuro che ci sia
- if(res.next()) {
- // Creo un nuovo Cliente, da valorizzare e poi restituire
- Cliente c = new Cliente();
- c.setId(res.getInt("id"));
- c.setNome(res.getString("nome"));
- c.setCognome(res.getString("cognome"));
- c.setUsr(res.getString("username"));
- c.setPsw(res.getString("password"));
- c.setDataNascita(res.getString("data_nascita"));
- c.setSaldo(new Saldo(res.getDouble("saldo")));
- c.setCodiceFiscale(res.getString("codice_fiscale"));
- stmt.close();
- conn.close();
- return c;
- }
- stmt.close();
- conn.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement