您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > linux/Unix相关 > java exp命令备份数据库 query
Stringcmd=exp用户名/密码@服务名file=C:\20111226160758.dmptables=(表名)query=\\\whereADDTIME=to_date('2011-12-0115:56:46','YYYY-MM-DDhh24:mi:ss')andADDTIME=to_date('2011-12-2615:56:46','YYYY-MM-DDhh24:mi:ss')\\\;(win7测试通过)//如果是windowsoscmd=cmd/c+cmd;//如果是linuxosbooleanshouldClose=false;Processprocess=null;try{process=java.lang.Runtime.getRuntime().exec(cmd/c+cmd);BufferedReaderb=newBufferedReader(newInputStreamReader(process.getErrorStream()));Stringline=null;booleanerr=false;errinfo=;while((line=b.readLine())!=null){System.out.println(line);if(err){errinfo=line;process.destroy();break;}if(line.indexOf(错误)0){err=true;}}intvalue=process.exitValue();if(value==0||(value==3&&!err)){this.setOperateStatus(数据库备份完成);System.out.println(数据库备份完成!);}else{System.out.println(exitvalue=+value);System.out.println(数据库备份失败!);this.setOperateStatus(数据库备份失败);}shouldClose=true;if(shouldClose)process.destroy();}catch(IOExceptione){//TODOAuto-generatedcatchblockshouldClose=true;e.printStackTrace();}finally{try{if(process!=null)process.waitFor();}catch(InterruptedExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}query参数说明其实文档中讲得很清楚:expscott/tigerTABLES=empQUERY=\WHEREjob=\'SALESMAN\'andsal\1600\Note:BecausethevalueoftheQUERYparametercontainsblanks,mostoperatingsystemsrequirethattheentirestringsWHEREjob=\'SALESMAN\'andsal\1600beplacedindoublequotationmarksormarkedasaliteralbysomemethod.Operatingsystemreservedcharactersalsoneedtobeprecededbyanescapecharacter.SeeyourOracleoperatingsystem-specificdocumentationforinformationaboutspecialandreservedcharactersonyoursystem.所有操作系统保留字符都要使用转义符号,看来()也需要转义。正确的写法:expscott/tigertables=skytestfile=test.dmpquery=\wheredt=to_date\(\'2007-09-22\',\'yyyy-mm-dd\'\)\(linux)expscott/tigertables=skytestfile=test.dmpquery=\wheredt=to_date('2007-09-22','yyyy-mm-dd')\(win7)任何os平台都适用的方法(推荐):使用parfile就不用担心这些格式问题oracleDBALNP01cattest.partables=skytestfile=test.dmpquery=wheredt=to_date('2007-09-22','yyyy-mm-dd')oracleDBALNP01exp/parfile=test.parExport:Release8.1.7.4.0-ProductiononWedSep1204:22:272007(c)Copyright2000OracleCorporation.Allrightsreserved.Connectedto:Oracle8iEnterpriseEditionRelease8.1.7.4.0-ProductionWiththePartitioningoptionJServerRelease8.1.7.4.0-ProductionExportdoneinUS7ASCIIcharactersetandUS7ASCIINCHARcharactersetAbouttoexportspecifiedtablesviaConventionalPath.....exportingtableSKYTEST1rowsexportedExportterminatedsuccessfullywithoutwarnings.不需要任何转义符既简洁又可以在多种操作系统平台上通用,推荐使用这种方式。命令行exp导出时对密码中含“)”的处理方法用户的密码为Rdy)Jl!S在windowsD:exptestuser/Rdy)Jl!S@oralocalowner=testuser在linuxnunix下,用$exptestuser/Rdy)Jl!Sowner=testuserIMPDPFLASHBACK_TIME中如何使用TO_TIMESTAMP参数,防止LRM-00116官方文档上查,参数文件中这样写to_timestamp()在命令行中直接这样写C:\DocumentsandSettings\yyyimpdpscott/tigertables=tdirectory=exp_dirnetwork_link=testflashback_time=to_timestamp('2009-01-0720:01:22','yyyy-mm-ddhh24:MI:SS')LRM-00116:')'后跟'yyyy-mm-ddhh24:'时出现语法错误总提示语法错误后来N长时间终于找到了解决办法AlternativelyyoucanusedFLASHBACK_TIMEparameterlikeonunix,flashback_time=\TO_TIMESTAMP\(\'16-05-200811:21:42\',\'DD-MM-YYYYHH24:MI:SS\'\)\Onwindows,flashback_time=\TO_TIMESTAMP('16-05-200813:24:26','DD-MM-YYYYHH24:MI:SS')\Usebackslash(\)beforespecialcharacter.所以改成C:\DocumentsandSettings\jiachliuimpdpscott/tigertables=tdirectory=exp_dirnetwork_link=testflashback_time=\to_timestamp('2009-01-0720:01:22','yyyy-mm-ddhh24:MI:SS')\执行成功--END
本文标题:java exp命令备份数据库 query
链接地址:https://www.777doc.com/doc-7028333 .html