QT backup oracle database and restore, use QProcess class

QT backup oracle database and restore, use QProcess class

Introduction

Use the QProcess class to start the cmd command line, enter the parameters to log in to the oracle database, and execute the SQL statements for backup and recovery.

Code sample, available for pro-test

The following is the backup code, which is similar when restoring, just replace the exp in the sql statement with imp. The
backup sql statement is analyzed, here is the backup according to the table:
host exp username/password@database namefile=save path tables( Table 1, Table 2...)

    QProcess t_Process(this);//应用程序类
    t_Process.setProcessChannelMode(QProcess::MergedChannels);
    QStringList argument;//参数列表
    argument << "/c" << "sqlplus";
    t_Process.start("cmd",argument);//启动cmd程序,传入参数
    bool isok = t_Process.waitForStarted();
    qDebug()<<"["<<__FILE__<<"]"<<__LINE__<<__FUNCTION__<<" "<<isok;//打印启动是否成功
    t_Process.write("system\r\n");//输入oracle账号
    t_Process.write("oracle\r\n");//输入oracle密码
    t_Process.write("host exp system/oracle@orcl file=d:/backup.dmp tables=(BASESTATIONDB,TEST_TABLE)\r\n");//输入备份sql语句
    t_Process.closeWriteChannel();//关闭输入通道
    t_Process.waitForFinished();
    QString strTemp=QString::fromLocal8Bit(t_Process.readAllStandardOutput());//获取程序输出
    t_Process.close();//关闭程序
    qDebug()<<"["<<__FILE__<<"]"<<__LINE__<<__FUNCTION__<<" "<<strTemp;//打印输出

Guess you like

Origin blog.csdn.net/weixin_40355471/article/details/107620082