Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package createjavamysql;
- import java.sql.*;
- import java.util.Scanner;
- /**
- *
- * @author Chiqidico
- */
- public class CreateJavaMySql {
- static boolean moreFields;
- public boolean isMoreFields() {
- return moreFields;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- try
- {
- String path = "jdbc:mysql://localhost/employees",
- user = "root",
- password = "Luzdiaz1";
- try
- {
- Class.forName ("com.mysql.jdbc.Driver");
- }
- catch (ClassNotFoundException cnfe)
- {
- System.out.println (cnfe.getMessage ());
- }
- Class.forName ("com.mysql.jdbc.Driver");
- Connection cn = DriverManager.getConnection (path, user, password);
- Statement st = cn.createStatement ();
- PreparedStatement ps;
- String sqlCommand = "";
- System.out.println("Enter database name?");
- String dName = sc.nextLine();
- System.out.println("Please enter table name?");
- String tName = sc.nextLine();
- System.out.println("Please enter field one?");
- String fName = sc.nextLine();
- System.out.println("Please enter field data type?");
- String fieldType = sc.nextLine();
- System.out.println("How many characters long?");
- String charLong = sc.nextLine();
- System.out.println("Would like to create another field True or False?");
- moreFields = sc.nextBoolean();
- String stuvw = fName + " " + fieldType + "(" + charLong + ")";
- st.executeUpdate("CREATE TABLE" + " " + tName + "(" + stuvw +");");
- while(moreFields == true){
- if(moreFields == false){
- System.exit(0);
- }
- System.out.println("Please enter field one?");
- fName = sc.nextLine();
- System.out.println("Please enter field data type?");
- fieldType = sc.nextLine();
- System.out.println("How many characters long?");
- charLong = sc.nextLine();
- System.out.println("Would you like to create another field True or False?");
- boolean moreFields = sc.nextBoolean();
- }}
- catch (ClassNotFoundException cnfe)
- {
- System.out.println (cnfe.getMessage ());
- }
- catch (SQLException sqe)
- {
- System.out.println (sqe.getMessage ());
- }}}
Add Comment
Please, Sign In to add comment