Guest User

Untitled

a guest
Oct 19th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package performance;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.Scanner;
  8.  
  9. public class firstques {
  10.  
  11. public static void main(String[] args) throws SQLException {
  12. // TODO Auto-generated method stub
  13.  
  14. try
  15. {
  16. Connection con;
  17. Statement stmt;
  18. Scanner sc;
  19.  
  20. sc=new Scanner(System.in);
  21. final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
  22. Class.forName("com.mysql.jdbc.Driver");
  23. con=DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","");
  24. stmt=con.createStatement();
  25.  
  26. System.out.println("Creating Table Please Wait...\n\n");
  27. Thread.sleep(1000);
  28. String sql="CREATE or replace TABLE `employee_data` (`name` text NOT NULL,`salary` int(255) NOT NULL,`id` int(125) NOT NULL,`dept` varchar(255) NOT NULL)";
  29. stmt.execute(sql);
  30. System.out.println("Employee Table Created Sucessfully.");
  31. System.out.println("\n\n Alter Table : ");
  32. System.out.println("\nEnter a new column name which you want to add into the employee table :\n(Don't add the space between column name)");
  33. String col=sc.next();
  34. sql="alter TABLE `employee_data` add "+col+" varchar(255)";
  35. stmt.execute(sql);
  36. System.out.println(col+ " Column is added in Employee Table");
  37. System.out.println("\n\n If you want to drop database then type Y : \n\n");
  38. String y=sc.next();
  39. if(y.equals("y")|| y.equals("Y"))
  40. {
  41. sql="drop TABLE `employee_data`";
  42. stmt.execute(sql);
  43. System.out.println("Employee table is deleted");
  44. }
  45. sc.close();
  46. con.close();
  47. stmt.close();
  48. }
  49. catch(Exception e)
  50. {
  51. System.out.println("Exception Occured : "+e);
  52. }
  53.  
  54. }
  55.  
  56. }
Add Comment
Please, Sign In to add comment