微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Oracle JDBC 可调用语句和 getMetadata 计数

如何解决Oracle JDBC 可调用语句和 getMetadata 计数

假设我有一个像下面这样的 pl/sql

  final Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
    String plsql = "" +
    " declare " +  
    "    p_id varchar2(20) := null; " +
    "    l_rc sys_refcursor;" +
    " begin " +
    "    p_id := ?; " +
    "    ? := 'input parameter was = ' || p_id;" +
    "    open l_rc for " +
    "        select 1a id,'hello' name from dual " +
    "        union " +
    "        select 2a,'peter' from dual; " +
    "    ? := l_rc;" +
    " end;";

    CallableStatement cs = c.prepareCall(plsql);
    cs.setString(1,"12345");
    cs.registerOutParameter(2,Types.VARCHAR);
    cs.registerOutParameter(3,OracleTypes.CURSOR);

    cs.execute();

这里一切正常,但我如何从中获得 Metadat.getColumnCount()?

我想达到什么目标? 而不是:

 ResultSet cursorResultSet = (ResultSet) cs.getobject(3);
        while (cursorResultSet.next ())
        {
            System.out.println (cursorResultSet.getString(1) + " " + cursorResultSet.getString(2));
        } 

我想查找元数据计数并在循环中打印一条记录的所有值,例如:

//伪代码

int x = callablestatement.Metadata.count();
String myRecord='';
while (cursorResultSet.next ()){
        for(int i=1; i<=x; i++){
          myRecord= myRecord+ " " + cursorResultSet.getString(i);
                               }
                               }

解决方法

获取结果集中的列数,需要使用

#Function to export data
def loop_function():

    #Search client
    searchCustomerButton = driver.find_element_by_xpath('//*[@id="ibSearchPatient"]')
    searchCustomerButton.click()

    #Click on show filter
    showCustomerFilter = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_RadGrid_Patienten_ctl00_ctl03_ctl01_PageSizeComboBox_Arrow"]')
    showCustomerFilter.click()

    time.sleep(5)

    #Click on show 1000
    selectCustomerFilter = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_RadGrid_Patienten_ctl00_ctl03_ctl01_PageSizeComboBox_DropDown"]/div/ul/li[6]')
    selectCustomerFilter.click()    

    #Loop client ID's
    followLoop = range(985,1015)
    for x in followLoop:

        xpath = '//*[@id="ctl00_CPH_Main_ctl00_RadGrid_Patienten_ctl00__'
        xpath += str(x)
        xpath += '"]/td[3]'
        
        #Click on cliënt ID
        driver.find_element_by_xpath(xpath).click()

        #Click on Zorgtraject
        zorgtrajectButton = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Top_ToolBar_MenuCurrentPage"]/div/ul/li[3]/a/span/span/span')
        zorgtrajectButton.click()

        #Loop Zorgtraject ID's
        followLoop2 = range(0,10)
        for i in followLoop2:
            try:
                xpath2 = '//*[@id="ctl00_CPH_Main_ctl00_RadGrid1_ctl00__'
                xpath2 += str(i)
                xpath2 += '"]/td[2]'

                #Click on Zorgtraject ID
                driver.find_element_by_xpath(xpath2).click()

                #Dossier button
                dossierButton = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Top_ToolBar_MenuCurrentPage"]/div/ul/li[5]/a/span/span/span')
                dossierButton.click()

                #Dropdown select
                dropdownSelector = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_radGridBehandelVerloop_ctl00_ctl03_ctl01_PageSizeComboBox_Arrow"]')
                dropdownSelector.click()

                #Prevent not interactable error
                time.sleep(1)

                #Select 50
                selectDropdown = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_radGridBehandelVerloop_ctl00_ctl03_ctl01_PageSizeComboBox_DropDown"]/div/ul/li[4]')
                selectDropdown.click()

                #Load files to be downloaded
                time.sleep(1)

                #Check all documents
                tickDossier = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_radGridBehandelVerloop_ctl00_ctl02_ctl01_headerChkboxPrint"]')
                tickDossier.click()

                #Click print
                printButton = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_btnPrintBehandelverloop"]')
                printButton.click()

                #Click on Zorgtraject ID
                zorgtrajectButton2 = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Top_ToolBar_MenuCurrentPage"]/div/ul/li[3]/a/span/span/span')
                zorgtrajectButton2.click()

            #If no Zorgtraject ID,start function over
            except NoSuchElementException:
                src = 'C:\\Users\\sohan\\Downloads'
                dst = 'C:\\Users\\sohan\\Documents\\Werk\\BIA Solutions\\Huid & Laserkliniek Delft\\Data\\' + str(x+1)

                files = [i for i in os.listdir(src) if i.startswith("behandel") and path.isfile(path.join(src,i))]
                for f in files:
                    shutil.move(path.join(src,f),dst)

                #Search client
                searchCustomerButton = driver.find_element_by_xpath('//*[@id="ibSearchPatient"]')
                searchCustomerButton.click()

                #Click on show filter
                showCustomerFilter = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_RadGrid_Patienten_ctl00_ctl03_ctl01_PageSizeComboBox_Arrow"]')
                showCustomerFilter.click()

                time.sleep(5)

                #Click on show 1000
                selectCustomerFilter = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_RadGrid_Patienten_ctl00_ctl03_ctl01_PageSizeComboBox_DropDown"]/div/ul/li[6]')
                selectCustomerFilter.click()     
                break

loop_function()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。