How to import MySQL database in Java
This article is about how to import MySQL database in Java, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
What can Java be used for? Java is mainly used in: 1. Web development; 2. Android development; 3. Client development; 4. Web page development; 5. Enterprise application development; 6. Java big data development; 7. Game development and so on.
First create a new database named test
Next, execute the following Java code:
Import java.io.File;import java.io.IOException / * MySQL database import * * @ author GaoHuanjie * / public class MySQLDatabaseImport {/ * Java implementation MySQL database import * * @ author GaoHuanjie * @ param hostIP MySQL database server address IP * @ param userName database user name * @ param password password required to enter the database * @ param importFilePath database file path * @ param sqlFileName database file name * @ param databaseName database name to be imported * @ return returns true to indicate that the import is successful Otherwise, false is returned. * / public static boolean importDatabase (String hostIP, String userName, String password, String importFilePath, String sqlFileName, String databaseName) {File saveFile = new File (importFilePath); if (! saveFile.exists ()) {/ / if saveFile.mkdirs () does not exist in the directory / / create a folder} if (! importFilePath.endsWith (File.separator)) {importFilePath = importFilePath + File.separator;} StringBuilder stringBuilder=new StringBuilder (); stringBuilder.append ("mysql") .append ("- h") .append (hostIP) StringBuilder.append ("- u") .append (userName) .append ("- p") .append (password); stringBuilder.append ("") .append (databaseName); stringBuilder.append ("