java로 sql서버 만드는 원리--2(미완성작품)
글쓴이: lfs / 작성시간: 수, 2019/01/09 - 2:55오후
import java.lang.*; import java.io.*; import java.util.*; public class sql{ public static void main(String[] args) throws Exception{ Database database=new Database(); Table table=new Table(); String Databasename; Scanner scanner=new Scanner(System.in); Console console=System.console(); while(true){ System.out.print("(Database)sql>"); String command=scanner.nextLine(); String[] Strcom=command.split(" "); if(Strcom.length==3){ if(Strcom[0].equals("creat")){ if(Strcom[1].equals("database")) database.Dmake(Strcom[2]); } else if(Strcom[0].equals("drop")){ if(Strcom[1].equals("database")) database.Ddel(Strcom[2]); } else{ System.out.println("잘못입력하셨습니다."); continue; } } else if(Strcom.length==2){ if(Strcom[0].equals("use")){ database.Dconnect(Strcom[1]); Databasename=Strcom[1]; //데이터베이스 이름을 기록 break; } else{ System.out.println("잘못입력하셨습니다."); continue; } } else if(Strcom.length==1){ if(Strcom[0].equals("show")) database.Dbmenu(); else if(Strcom[0].equals("quit")){ System.out.println("데이터베이스 종료"); System.exit(0); } else{ System.out.println("잘못입력하셨습니다."); continue; } } else{ System.out.println("잘못입력하셨습니다."); continue; } } while(true){ System.out.println("(Table)sql>"); String command_two=console.readLine(); String[] Strcom_two=command.split(" "); if(Strcom_two.length==8){ if(Strcom_two[0].equals("alter")){ if(Strcom_two[1].equals("table")){ if(Strcom_two[3].equals("change")){ if(Strcom_two[4].equals("column")){ Tselect tselect=new Tselect(Strcom_two[2],Strcom_two[5],Strcom_two[7],Strcom_two[6]); } } } } } } } } class Database{ List<String> Dlist=new ArrayList<String>(); public void Dmake(String args) throws Exception{ String crname=args; Dlist.add(crname); } public void Ddel(String args) throws Exception{ String dlname=args; Dlist.remove(dlname); } public void Dbmenu() throws Exception{ if(Dlist.size()==0){ Dlist.add(" "); } System.out.println("+----------+"); for(int i=0;i<Dlist.size();i++){ String title=Dlist.get(i); System.out.printf("|%-10s|\n",title); } System.out.println("+----------+"); } public void Dconnect(String args) throws Exception{ for(String str:Dlist){ if(str.equals(args)){ System.out.println(str+"데이터베이스 선택"); } } } } class Table { List<String> Tlist=new ArrayList<String>(); int SIZE; String[][] bstr=new String[1][SIZE]; Integer[][] bint=new Integer[1][SIZE]; String cott[SIZE]; Scanner scanner=new Scanner(System.in); public void Tmake(String args) throws Exception{ String crname=args; Tlist.add(crname); //입력 for(int j=0;j<1;j++){ for(int i=0;i<3;i++){ System.out.print("필드 속성값:"); String icon=console.readLine(); String cott[i]=icon; String[] names=icon.split(" "); String haha=new String(names[0]); String gaga=new String(names[1]); //초기값할당 if(gaga.equals("String")){ bstr[j][i]=new String(" "); } else if(gaga.equals("Integer")){ bint[j][i]=new Integer(0); } } } } public void Tdel(String args) throws Exception{ String dlname=args; Tlist.remove(dlname); } public void Tbmenu(String args) throws Exception{ if(Tlist.size()==0){ Tlist.add(" "); } System.out.println("+----------+"); for(int i=0;i<Tlist.size();i++){ String title=Tlist.get(i); System.out.printf("|%-10s|\n",title); } System.out.println("+----------+"); } public void Talter(String args) throws Exception{ } } class Tselect extends Table{ Tselect(String tablename,String fieldname,String fieldtype,String newfieldname){ }//테이블 필드 변경 생성자 Tselect(String tablename,String fieldname,String fieldtype){ }//테이블 필드 추가 생성자 Tselect(String tablename,String fieldname){ }//테이블 필드 삭제 생성자 }
구문해석 알고리즘이 있다지만 어려운 알고리즘이라
if문을 이용하여 만들어봤습니다. 미완성 작품인 이유는
Arraylist컬렉션의 add()메소드가 버그가 있어서 못
만들었습니다. 이점 이해해 주시길....
Forums:
댓글 달기