Guest User

Untitled

a guest
Aug 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package createjavamysql;
  6.  
  7. import java.sql.*;
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author Chiqidico
  13. */
  14. public class CreateJavaMySql {
  15. static boolean moreFields;
  16.  
  17. public boolean isMoreFields() {
  18. return moreFields;
  19.  
  20. }
  21. /**
  22. * @param args the command line arguments
  23. */
  24. public static void main(String[] args) {
  25.  
  26. Scanner sc = new Scanner(System.in);
  27. try
  28. {
  29. String path = "jdbc:mysql://localhost/employees",
  30. user = "root",
  31. password = "Luzdiaz1";
  32. try
  33. {
  34. Class.forName ("com.mysql.jdbc.Driver");
  35. }
  36. catch (ClassNotFoundException cnfe)
  37. {
  38. System.out.println (cnfe.getMessage ());
  39. }
  40. Class.forName ("com.mysql.jdbc.Driver");
  41. Connection cn = DriverManager.getConnection (path, user, password);
  42. Statement st = cn.createStatement ();
  43. PreparedStatement ps;
  44. String sqlCommand = "";
  45.  
  46. System.out.println("Enter database name?");
  47. String dName = sc.nextLine();
  48. System.out.println("Please enter table name?");
  49. String tName = sc.nextLine();
  50.  
  51. System.out.println("Please enter field one?");
  52. String fName = sc.nextLine();
  53. System.out.println("Please enter field data type?");
  54. String fieldType = sc.nextLine();
  55. System.out.println("How many characters long?");
  56. String charLong = sc.nextLine();
  57. System.out.println("Would like to create another field True or False?");
  58. moreFields = sc.nextBoolean();
  59. String stuvw = fName + " " + fieldType + "(" + charLong + ")";
  60. st.executeUpdate("CREATE TABLE" + " " + tName + "(" + stuvw +");");
  61. while(moreFields == true){
  62. if(moreFields == false){
  63. System.exit(0);
  64. }
  65. System.out.println("Please enter field one?");
  66. fName = sc.nextLine();
  67. System.out.println("Please enter field data type?");
  68. fieldType = sc.nextLine();
  69. System.out.println("How many characters long?");
  70. charLong = sc.nextLine();
  71. System.out.println("Would you like to create another field True or False?");
  72. boolean moreFields = sc.nextBoolean();
  73. }}
  74. catch (ClassNotFoundException cnfe)
  75. {
  76. System.out.println (cnfe.getMessage ());
  77. }
  78. catch (SQLException sqe)
  79. {
  80. System.out.println (sqe.getMessage ());
  81. }}}
Add Comment
Please, Sign In to add comment