기타

게임프로젝트 SQL문 생성코드

lipnus 2019. 3. 7. 22:43
반응형

게임 데이터 관리할 때 사용



퀴즈


/**
* 반드시 3의 배수
*/
public class Choice {
public static void main(String[] args) throws Exception{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;


while( (line = br.readLine()) !=null ){

//퀴즈넣기
String[] voca = line.split("\t");
System.out.printf("INSERT INTO quiz (music_pk, writer) SELECT pk, writer FROM music WHERE music.title='%s';\n", voca[0]);
System.out.println("SELECT @quiz_pk := LAST_INSERT_ID();");

//선택지
System.out.printf("INSERT INTO choice (quiz_pk, choice_text, truth) VALUES (@quiz_pk, '%s', %s);\n", voca[1], voca[2]);

voca = br.readLine().split("\t");
System.out.printf("INSERT INTO choice (quiz_pk, choice_text, truth) VALUES (@quiz_pk, '%s', %s);\n", voca[1], voca[2]);

voca = br.readLine().split("\t");
System.out.printf("INSERT INTO choice (quiz_pk, choice_text, truth) VALUES (@quiz_pk, '%s', %s);\n", voca[1], voca[2]);
}
}
}



음악

public class Main {
public static void main(String[] args) throws Exception{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;


while( (line = br.readLine()) !=null ){

System.out.printf("INSERT INTO `music` (`title`, `initial`, `singer`, `path`, `use_init`, `writer`) VALUES ");
String[] voca = line.split("\t");

System.out.printf("(");
for(int i=0; i<voca.length; i++){
if(i<voca.length-1) System.out.printf(" '%s', ", voca[i]);
else System.out.printf(" '%s' );\n", voca[i]);
}
}
}
}


반응형