Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication;
  7. import java.sql.*;
  8. import java.util.Scanner;
  9. /**
  10. *
  11. * @author Student
  12. */
  13. public class JavaApplication {
  14. public static final String USERNAME="root";
  15. public static final String PASSWORD="";
  16. public static final String CONN_STRING="jdbc:mysql://localhost:3306/db2";
  17.  
  18.  
  19. /**
  20. * @param args the command line arguments
  21. */
  22. public static void main(String[] args) {
  23. String Fname, Lname, City;
  24. int EID, Zip, Salary, Age;
  25.  
  26. Scanner s = new Scanner(System.in);
  27. System.out.print("Enter First Name: ");
  28. Fname = s.nextLine();
  29. System.out.print("Enter Last Name: ");
  30. Lname = s.nextLine();
  31. System.out.print("Enter City: ");
  32. City = s.nextLine();
  33. System.out.print("Enter Zip Code: ");
  34. Zip = s.nextInt();
  35. System.out.print("Enter Age: ");
  36. Age = s.nextInt();
  37. System.out.print("Enter Salary: ");
  38. Salary = s.nextInt();
  39.  
  40. Connection conn=null;
  41. try{
  42. conn=DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
  43. System.out.println("Connected");
  44. Statement stmt=(Statement)conn.createStatement();
  45.  
  46.  
  47. String insert="INSERT INTO `db2`.`db1employees` (`EmployeeID`, `FirstName`, `LastName`, `City`, `Zipcode`, `Age`, `Salary`) VALUES (NULL, '"+Fname+"', '"+Lname+"', '"+City+"', '"+Zip+"', '"+Age+"', '"+Salary+"');";
  48. stmt.executeUpdate(insert);
  49.  
  50. }
  51. catch(SQLException e){
  52. System.err.println(e);
  53. }
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement