Guest User

Untitled

a guest
Aug 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import java.util.Scanner;
  6.  
  7. public class ConsoleDB
  8. {
  9. public static void main(String[] args) throws SQLException
  10. {
  11. int pincode,id;
  12. String fname,lname,dept;
  13.  
  14. Scanner s = new Scanner(System.in);
  15.  
  16. System.out.print("Enter Employee ID : ");
  17. id = s.nextInt();
  18. System.out.print("Enter First Name : ");
  19. fname = s.next();
  20. System.out.print("Enter Last Name : ");
  21. lname = s.next();
  22. System.out.print("Enter Department : ");
  23. dept = s.next();
  24. System.out.print("Enter Pincode : ");
  25. pincode = s.nextInt();
  26.  
  27. String url = "jdbc:mysql://localhost/javadb";
  28. String user = "root";
  29. String pass = "XXXXXX"; <----your Localhost password
  30. String insrt = "insert into student value("+id+",\""+fname+"\",\""+lname+"\",\""+dept+"\","+pincode+");";
  31. Connection conn = DriverManager.getConnection(url,user,pass);
  32. Statement st = conn.createStatement();
  33. int r = st.executeUpdate(insrt);
  34.  
  35. }
  36. }
Add Comment
Please, Sign In to add comment