Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Login_Registration_Project;
- import java.sql.*;
- import java.util.Scanner;
- import java.lang.*;
- /**
- * Created by Salek on 17.01.2017.
- */
- public class MysqlTest {
- public static void main (String[] args) {
- String url = "jdbc:mysql://localhost:3306/javabase";
- String user = "java";
- String passwd = "password";
- 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
- 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("Last Name:");
- String v1 = sc.nextLine();
- System.out.println("First Name");
- String v2 = sc.nextLine();
- System.out.println("Address"); // This one will be problematic since nextLine() can't have spaces and addresses usually do
- String v3 = sc.nextLine();
- System.out.println("Email");
- String v4 = sc.nextLine();
- System.out.println("City");
- String v5 = sc.nextLine();
- System.out.println("Pesel");
- long v6 = sc.nextLong();
- System.out.println("Password");
- String v7 = sc.nextLine();
- System.out.println("Login is your pesel number.");
- int v8 = (int) (Math.random() * 10 + 100);
- // sc.nextLine();
- String myQuery = ("insert into Patients (PatientID, LastName, FirstName, Address, Email, City, Pesel) " +
- "values ('" + v8 + "','" + v1 + "','" + v2 + "','" + v3 + "', '" + v4 + "','" + v5 + "','" + v6 + "')");
- String myQuery1 = ("insert into Shadow (PatientID, Password, Pesel)" +
- "values ('" + v8 + "','" + v7 + "','" + v6 + "')");
- System.out.println(myQuery);
- System.out.println(myQuery1);
- myStmt.executeUpdate(myQuery);
- myStmt.executeUpdate(myQuery1);
- System.out.println("Insert completed!");
- }
- catch (Exception exc) {
- exc.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement