如果mysql中不存在数据库名,如何查找错误。数据库名类似于演示。我提供以下示例代码
String dumpCommand = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump -h"+hostName+user+demo(//database name);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(dumpCommand);
InputStream in = proc.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String line =null;
while((line=br.readLine())!=null)
{
//.....
}即使mysql中不包含数据库名,此代码也将成功运行。
发布于 2010-02-19 07:37:21
以下是两种错误:
mysqldump: Got错误: 1045:在尝试连接时拒绝用户'root'@'localhost‘(使用密码:否)的访问
和
mysqldump: Got错误: 1049:当选择数据库时未知数据库'database1name‘
基于此,您可以执行以下操作
String output = IOUtils.toString(inputStream)
int errIdx = output.indexOf("mysqldump: Got error: ");
if (errIdx != -1) {
throw new RuntimeException("Failed to perform dump. The error message is: "
+ output.substring(idx));
}如果您不想使用IOUtils (来自公野),您可以使用while(..)方法并在那里进行上述检查。
https://stackoverflow.com/questions/2294683
复制相似问题