Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.progettolab.database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Registrazione {
- private String email;
- private String username;
- private String password;
- private String passR;
- public String execute() {
- String ret;
- Connection conn = null;
- Statement stmt = null;
- try{
- String URL = "jdbc:mysql://localhost:3308/tutorial";
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(URL, "root", "Fabio1992");
- stmt = conn.createStatement();
- if(getPassR().equals(password)){
- ret = "ok";
- String sql = "INSERT INTO tutorial.utenti (email, user, password) values"
- + "('" + getEmail() + "', '" + getUsername() + "', '" + getPassword() + "')";
- stmt.executeUpdate(sql);
- } else {
- ret = "wrong";
- }
- } catch (Exception e) {
- e.printStackTrace();
- ret = "errore";
- } finally {
- try{
- if(stmt!=null)
- conn.close();
- }catch(SQLException se){
- }
- if (conn != null) {
- try {
- conn.close();
- } catch (Exception e) {
- }
- }
- }
- return ret;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getPassR() {
- return passR;
- }
- public void setPassR(String passR) {
- this.passR = passR;
- }
- }
Add Comment
Please, Sign In to add comment