Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Login_Registration_Project;
- import java.sql.*;
- import java.util.*;
- import java.lang.*;
- /**
- * Created by Salek on 17.01.2017.
- */
- public class Registration {
- public static void main (String[] args) {
- String url = "jdbc:mysql://localhost:3306/javabase";
- String user = "java";
- String passwd = "password";
- Scanner sc = new Scanner(System.in);
- System.out.println("In order to register to the Clinic you need to create an account first, please enter your data.");
- System.out.println("First Name:");
- String FirstName = sc.nextLine();
- System.out.println("Last Name");
- String LastName = sc.nextLine();
- System.out.println("Address");
- String Address = sc.nextLine();
- System.out.println("Email");
- String Email = sc.nextLine();
- System.out.println("City");
- String City = sc.nextLine();
- System.out.println("Password");
- String Password = sc.nextLine();
- System.out.println("Enter your Pesel number it will be your login to our Clinic so please make sure it is written correctly.");
- long Pesel = sc.nextLong();
- int PatientID = (int) (Math.random() * 10);
- try {
- // 1. Get a connection to the DB
- Connection myConn = DriverManager.getConnection(url, user, passwd);
- // 2. Create a statement
- Statement myStmt = myConn.createStatement();
- // 3. Execute SQL query
- String myQuery = ("insert into Patients (PatientID, LastName, FirstName, Address, Email, City, Pesel) " +
- "values ('" + PatientID + "','" + LastName + "','" + FirstName + "','" + Address + "', '" +
- Email + "','" + City + "','" + Pesel + "')");
- String myQuery1 = ("insert into Shadow (PatientID, Password, Pesel)" +
- "values ('" + PatientID + "','" + Password + "','" + Pesel + "')");
- // System.out.println(myQuery);
- // System.out.println(myQuery1);
- myStmt.executeUpdate(myQuery);
- myStmt.executeUpdate(myQuery1);
- System.out.println("Register completed successfully!");
- }
- catch (Exception e3) {
- System.out.println("Oops, something went wrong...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement