Guest User

Untitled

a guest
Mar 15th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. package com.progettolab.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class Registrazione {
  9.  
  10.     private String email;
  11.     private String username;
  12.     private String password;
  13.     private String passR;
  14.  
  15.     public String execute() {
  16.         String ret;
  17.         Connection conn = null;
  18.         Statement stmt = null;
  19.  
  20.         try{
  21.             String URL = "jdbc:mysql://localhost:3308/tutorial";
  22.             Class.forName("com.mysql.jdbc.Driver");
  23.             conn = DriverManager.getConnection(URL, "root", "Fabio1992");
  24.             stmt = conn.createStatement();
  25.             if(getPassR().equals(password)){
  26.                 ret = "ok";
  27.                 String sql = "INSERT INTO tutorial.utenti (email, user, password) values"
  28.                         + "('" + getEmail() + "', '" + getUsername() + "', '" + getPassword() + "')";
  29.                 stmt.executeUpdate(sql);
  30.             } else {
  31.                 ret = "wrong";
  32.             }
  33.  
  34.         } catch (Exception e) {
  35.             e.printStackTrace();
  36.             ret = "errore";
  37.         } finally {
  38.             try{
  39.                 if(stmt!=null)
  40.                     conn.close();
  41.             }catch(SQLException se){
  42.             }
  43.             if (conn != null) {
  44.                 try {
  45.                     conn.close();
  46.                 } catch (Exception e) {
  47.                 }
  48.             }
  49.         }
  50.         return ret;
  51.     }
  52.  
  53.     public String getEmail() {
  54.         return email;
  55.     }
  56.  
  57.     public void setEmail(String email) {
  58.         this.email = email;
  59.     }
  60.  
  61.     public String getUsername() {
  62.         return username;
  63.     }
  64.  
  65.     public void setUsername(String username) {
  66.         this.username = username;
  67.     }
  68.  
  69.     public String getPassword() {
  70.         return password;
  71.     }
  72.  
  73.     public void setPassword(String password) {
  74.         this.password = password;
  75.     }
  76.  
  77.     public String getPassR() {
  78.         return passR;
  79.     }
  80.  
  81.     public void setPassR(String passR) {
  82.         this.passR = passR;
  83.     }
  84. }
Add Comment
Please, Sign In to add comment