public static ArrayList<String> readFileByLines(String filePath)  throws Exception{
ArrayList<String> sqlList = new ArrayList<String>();
StringBuffer str = new StringBuffer();
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(
new FileInputStream(filePath), "UTF-8"));
String tempString = null;
int line = 1;
while ((tempString = reader.readLine()) != null) {
str = str.append(" " + tempString);
line++;
}
reader.close();
String[] sqlArr = str.toString().split(";");
for (int i = 0; i < sqlArr.length; i++) {
sqlList.add(sqlArr[i].toString());
}
return sqlList;
} public static void test3(String sqlPath) throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ArrayList<String> sqlList = (ArrayList) readFileByLines(sqlPath);
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "123456");
conn.setAutoCommit(false);
stmt = conn.createStatement();
for(int i=0;i<sqlList.size();i++){
String sql = sqlList.get(i);
stmt.addBatch(sql);
}
//stmt.addBatch("drop table if exists b");
stmt.executeBatch();
conn.commit(); // 提交
 drop table if exists c 
 CREATE TABLE  `c` (   `id` int(11) NOT NULL,   `name` varchar(255) DEFAULT NULL,   `email` varchar(255) DEFAULT NULL,   `hiredate` datetime DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8