I need to get the installation path of MySQL in order to perform the export and import the database through java code. currently am working with eclipse. I need to get the installation path in a String variable "mySqlPath".
File fMysqlPath = new File("C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\");
String executeCmd = "mysqldump -u " + Constants.DB_USER + " -p" +
Constants.DB_PASSWORD + " " + Constants.DB_NAME + " -r " +
FilePath + "\\" + FileName;
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd, null, fMysqlPath);
This is what I have done. This has a dependency problem.
How can I solve this?
Have you tried this:
import java.sql.*;
import javax.sql.*;
public class MysqlPathFinderDemo{
public static void main(String args[]){
String dbtime;
String dbUrl = "jdbc:mysql://your.database.domain/yourDBname";
String dbClass = "com.mysql.jdbc.Driver";
String query = "Select * FROM users";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection (dbUrl);
Statement stmt = con.createStatement();
res = Myconnection.st.executeQuery("select @@datadir");
String Mysqlpath = "";
while(res.next()){
Mysqlpath=res.getString(1) ;
}
Mysqlpath = Mysqlpath.replace("Data", "bin");
System.err.println("Mysql path is :"+a);
} catch(Exception ee) {
}
}
}