Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. package Login_Registration_Project;
  2.  
  3. import java.sql.*;
  4. import java.util.*;
  5. import java.lang.*;
  6.  
  7.  
  8. /**
  9.  * Created by Salek on 17.01.2017.
  10.  */
  11. public class Registration {
  12.  
  13.     public static void main (String[] args) {
  14.  
  15.         String url = "jdbc:mysql://localhost:3306/javabase";
  16.         String user = "java";
  17.         String passwd = "password";
  18.  
  19.         Scanner sc = new Scanner(System.in);
  20.  
  21.         System.out.println("In order to register to the Clinic you need to create an account first, please enter your data.");
  22.         System.out.println("First Name:");
  23.         String FirstName = sc.nextLine();
  24.         System.out.println("Last Name");
  25.         String LastName = sc.nextLine();
  26.         System.out.println("Address");
  27.         String Address = sc.nextLine();
  28.         System.out.println("Email");
  29.         String Email = sc.nextLine();
  30.         System.out.println("City");
  31.         String City = sc.nextLine();
  32.         System.out.println("Password");
  33.         String Password = sc.nextLine();
  34.         System.out.println("Enter your Pesel number it will be your login to our Clinic so please make sure it is written correctly.");
  35.         long Pesel = sc.nextLong();
  36.  
  37.  
  38.  
  39.         int PatientID = (int) (Math.random() * 10);
  40.  
  41.  
  42.         try {
  43.             //  1. Get a connection to the DB
  44.             Connection myConn = DriverManager.getConnection(url, user, passwd);
  45.             //  2. Create a statement
  46.             Statement myStmt = myConn.createStatement();
  47.             //  3. Execute SQL query
  48.  
  49.  
  50.             String myQuery = ("insert into Patients (PatientID, LastName, FirstName, Address, Email, City, Pesel) " +
  51.                     "values ('" + PatientID +  "','" + LastName +  "','" + FirstName +  "','" + Address +  "', '" +
  52.                     Email +  "','" + City +  "','" + Pesel + "')");
  53.  
  54.  
  55.             String myQuery1 = ("insert into Shadow (PatientID, Password, Pesel)" +
  56.                     "values ('" + PatientID + "','" + Password + "','" + Pesel + "')");
  57.  
  58. //            System.out.println(myQuery);
  59. //            System.out.println(myQuery1);
  60.  
  61.             myStmt.executeUpdate(myQuery);
  62.             myStmt.executeUpdate(myQuery1);
  63.  
  64.             System.out.println("Register completed successfully!");
  65.  
  66.         }
  67.         catch (Exception e3) {
  68.             System.out.println("Oops, something went wrong...");
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement