我无法与 java 上的 mysqldump.exe 集成
我正在尝试通过 MySQL 附带的 mysqldump 实用程序备份 MySQL 数据库。我的代码是在JAVA上。但它没有返回任何内容,所以我无法备份数据库。下面是用于执行此操作的函数:
public String getServerDumpData()
{
new Database("Database.ini");
StringBuilder dumpdata = new StringBuilder();
String execline = "";
try {
if(Database.ConnectToDatabase()){
// Set path. Set location of mysqldump
// For example: current user folder and lib subfolder
if( HelpersToolbox.IsWindows() ){
execline = System.getProperty("user.dir") + "\\mysql\\mysqldump.exe";
}else{
execline = System.getProperty("user.dir") + "\\lib\\mysqldump.exe";
}
// Usage: mysqldump [OPTIONS] database [tables]
// OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
// OR mysqldump [OPTIONS] --all-databases [OPTIONS]
String command[] = new String[]{ execline,
"--host=" + Database.DbServer,
"--port=" + Database.DbPort,
"--user=" + Database.DbUsername,
"--password=" + Database.DbPassword,
"--compact",
"--complete-insert",
"--extended-insert",
"--skip-comments",
"--skip-triggers",
Database.DbName };
// Run mysqldump
ProcessBuilder pb = new ProcessBuilder(command);
Process process = pb.start();
InputStream in = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int count;
char[] cbuf = new char[STREAM_BUFFER];
// Read datastream
while ((count = br.read(cbuf, 0, STREAM_BUFFER)) != -1){
dumpdata.append(cbuf, 0, count);
}
// Close
br.close();
in.close();
}
} catch (Exception ex) {
ex.printStackTrace();
return "";
}
return dumpdata.toString();
}
它无法访问末尾的循环。那么这里有什么问题呢?
Am trying to backup MySQL database via mysqldump utility attached with MySQL. My code is on JAVA.But it returns nothing so i cannot backup the database. Here is the function used to do that :
public String getServerDumpData()
{
new Database("Database.ini");
StringBuilder dumpdata = new StringBuilder();
String execline = "";
try {
if(Database.ConnectToDatabase()){
// Set path. Set location of mysqldump
// For example: current user folder and lib subfolder
if( HelpersToolbox.IsWindows() ){
execline = System.getProperty("user.dir") + "\\mysql\\mysqldump.exe";
}else{
execline = System.getProperty("user.dir") + "\\lib\\mysqldump.exe";
}
// Usage: mysqldump [OPTIONS] database [tables]
// OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
// OR mysqldump [OPTIONS] --all-databases [OPTIONS]
String command[] = new String[]{ execline,
"--host=" + Database.DbServer,
"--port=" + Database.DbPort,
"--user=" + Database.DbUsername,
"--password=" + Database.DbPassword,
"--compact",
"--complete-insert",
"--extended-insert",
"--skip-comments",
"--skip-triggers",
Database.DbName };
// Run mysqldump
ProcessBuilder pb = new ProcessBuilder(command);
Process process = pb.start();
InputStream in = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int count;
char[] cbuf = new char[STREAM_BUFFER];
// Read datastream
while ((count = br.read(cbuf, 0, STREAM_BUFFER)) != -1){
dumpdata.append(cbuf, 0, count);
}
// Close
br.close();
in.close();
}
} catch (Exception ex) {
ex.printStackTrace();
return "";
}
return dumpdata.toString();
}
It cannot access the loop at the end . So what's the problem here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须读取这些数据或将其与输出流合并。
您拥有错误流上的数据,在开始该过程之前,
You have the data on the error stream which you either also have to read or merge with the output stream by using
before starting the process.