需求是:安装操作,首先通过system账号得到connection,然后创建一个用户并且赋予DBA权限,接着用cmd导入dmp文件到数据库中。现在出现的问题是本地的导入成功了,但是远程导入数据库不行。我想知道是否可以远程导入数据库?如何解决等
下面是导入代码
                  String impString="imp "+dbUserName+"/"+dbPassword+"@"+dbUrlName+" full=y file="+filePath+" ";
System.out.println(impString);
String [] cmds=new String[3];
cmds[0]="cmd";
cmds[1]="/C";
cmds[2]=impString;
Process process=null;
boolean shouldClose=false;
try {
process=Runtime.getRuntime().exec(cmds);
InputStreamReader isr=new InputStreamReader(process.getErrorStream());
BufferedReader br=new BufferedReader(isr);
String line=null;
while((line=br.readLine())!=null){
System.out.println(line);
if(line.indexOf("????")!=-1){
shouldClose=true;
break;
}
}
} catch (IOException e) {
shouldClose=true;
e.printStackTrace();
}

if(shouldClose){
process.destroy();
int exitVal;
try {
exitVal=process.waitFor();
System.out.println(exitVal);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

解决方案 »

  1.   

    IMP-00058: 遇到 ORACLE 错误 12154
    ORA-12154: TNS: 无法解析指定的连接标识符
    IMP-00000: 未成功终止导入这是远程导入数据库时 后台的输出
      

  2.   

    你導入的方法應該不對。
    你應該首先在本地安裝oracle客戶端,版本最好和服務器端的oracle本版一致(不能低于)。本地oracle客戶端需要配置一下,不然你單純使用本地oracle客戶端也是無法連接遠端的oracle服務器的。
    配置好了後,在java中調用外部命令試試。導入的命令是:impdp userid='sys/sysadmin@orcl as sysdba' schemas=PMS directory=DATA_PUMP_DIR dumpfile=PMS_EMP.DMP logfile=export.log
    version=10.2.0.1.0
      

  3.   

    你这个只是调用cmd命令而已
    先不看程序,你用cmd看能不能执行