admin管理员组文章数量:1277393
I have to import a database through java, I have the database in file and I have to be able to read the file and directly import this database to mySQL, how can I do it? The code below is to read the sql file, but I don't know how to import it to mysql once the file is read.
public static void importBD (Connection connection) throws SQLException{
Statement s= connection.createStatement();
s.executeUpdate("USE example");
s.close();
}
public static void importDataBase(Connection connection) throws SQLException, IOException{
BufferedReader bf = new BufferedReader(new FileReader("example.sql"));
Statement s = connection.createStatement();
String line="", db="";
while((line=bf.readLine())!=null){
if(!line.startsWith("--") && !line.equals("")){
db += line;
if(db.contains(";")){
s.execute(db);
db = "";
}
}
}
s.close();
bf.close();
}
How can I do it?
本文标签: jdbcHow import database using JavaStack Overflow
版权声明:本文标题:jdbc - How import database using Java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741258964a2367237.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论