コード例 #1
1
 /*
  * create method, that read from a txt file and read the MySQL language and write to the database.
  */
 public void createDB() {
   try {
     BufferedReader br = new BufferedReader(new FileReader("db_schema.txt"));
     String line = null;
     StringBuilder sb = new StringBuilder();
     while ((line = br.readLine()) != null) {
       sb.append(line);
       if (sb.length() > 0
           && sb.charAt(sb.length() - 1) == ';') { // see if it is the end of one line of command
         statement.executeUpdate(sb.toString());
         sb = new StringBuilder();
       }
     }
     br.close();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }