I found that it is probably impossible to do it yet without adding additional tools and libraries.
We can do it by splitting the SQL file into smaller SQL files, each containing just one SQL command and then initiating a loop to execute all those files at once. I'd tried it and it works. It certainly does.
The following is the code I used to do that :
import javax.swing.* ;
import java.sql.* ;
import java.io.* ;
public class LoadSQLFile {
public static void main(string args[ ]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
String password = JOptionPane.showInputDialog(null, "We need your MySQL Password to run the application. Please enter it here.", " MySQL Password ?", JOptionPane.QUESTION_MESSAGE) ;
Class.forName("java.sql.Driver") ;
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/MyDB", "root", password) ;
Statement stmt = conn.createStatement() ;
int i = 0 ;
for(i=1;i<=16;i++) {
FileReader fr = new FileReader("src//sql_files//BCK"+i+".sql") ;
BufferedReader br = new BufferedReader(fr) ;
stmt.execute(br.readLine()) ;
}
stmt.close();
conn.close();
JOptionPane.showMessageDialog(null, " Records Successfully Inserted into database !", "Success !", 1) ;
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e, "ERROR", JOptionPane.ERROR_MESSAGE) ;
}
}
});
}
}
I was to execute SQL files stored in my project's source folder inside a package named "sql_files". The names of the files are - BCK1.sql, BCK2.sql, ...., BCK16.sql. Each file contained just one SQL file in just first line. It worked just fine for me.
I used the MySQL JDBC Driver for this.