java 执行MySQL脚本小干货

public static void main(String[] args){
String url = "jdbc:mysql://112.124.121.34:3306/shihou_event";
String username = "esports";
String password = "somethingyouxiduo";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver).newInstance();
   Connection conn = (Connection) DriverManager.getConnection(url, username, password);
   ScriptRunner runner = new ScriptRunner(conn);
   runner.setErrorLogWriter(null);
   runner.setLogWriter(null);
   runner.runScript(Resources.getResourceAsReader("db_task.sql"));
}catch(Exception e){
System.out.println("=============");
}

}

你可能感兴趣的:(下上篇,数据访问层)