package Test;
/**
* 1.通过输入数字来判断进行那种操作
* 2.紧接着再输入sql语句,执行操作
*/
import Util.MysqlUtil;
import java.sql.SQLException;
import java.util.Scanner;
public class Test {
private String sql;//the sql that would be executed
private int command;//the command
private static final String hint[]={"exit","describe the tables","select all data from tables","insert into tables",
"delete data from tables","Please select the type of operation"};//the hint of input
public static void main(String []args) throws SQLException, ClassNotFoundException {
Test test = new Test();
MysqlUtil mysqlUtil = new MysqlUtil();
test.printHint();
do {
test.command = test.getCommand();//get command
switch(test.command){
case 0:System.out.println(hint[test.command]);
return;
case 1:System.out.println(hint[test.command]);
test.sql = test.getSql();
mysqlUtil.printTableStructure(mysqlUtil.getConnect(),test.sql);break;
case 2:System.out.println(hint[test.command]);
test.sql = test.getSql();
mysqlUtil.doQuerySQL(mysqlUtil.getConnect(),test.sql);break;
case 3:System.out.println(hint[test.command]);
test.sql = test.getSql();
mysqlUtil.deleteSQL(mysqlUtil.getConnect(),test.sql);break;
}
}while(test.getCommand()!=-1);
}
public void printHint(){
int count = 0;
for(String s:hint){
System.out.println(count+"."+s);
count++;
}
}
public String getSql(){
Scanner scanner = new Scanner(System.in);//input the commad
System.out.println("请输入SQL语句");
String sql = scanner.nextLine();
return sql;
}
public int getCommand(){
Scanner scanner = new Scanner(System.in);//input the commad
int command = scanner.nextInt();
return command;
}
public void setCommand(Integer command){
this.command = command;
}
}
//test.printHint();//print the hint
//test.setCommand(test.getInput());//get the type of operation
//未完成的功能 --> 通过选项直接修改
// switch (test.command){
// case 1:return;
// case 2:test.opereate(test.command);break;
// case 3:
//
}