Forum Discussion

slipperysucker's avatar
slipperysucker
New Contributor
13 years ago

write jdbc data to text file.

Dear All,

Can anyone help me with my problem. I am currently using SOAPUI to test webservices (some of my services are Asynchro, while others are Synchro) and I am very new to SOAPUI. I have searched the forum with keyword like (JDBC, write, data, into, text file or combinations from these words.)and I am currently going through the forum page by page as well.

System information:
Windows7 (currently used and for office environment).
Oracle SQL developer (2.1.0.63)
SOAPUI (4.0.1)

My problem is: (this is an Asynchro service – thus no response.)
(precondition: all my inputs(properties) are set in a text file, which I declare on the project level.)
-I use SOAPUI project to create a document. When this is done, the document is created and in the Oracle sql developer database the document is registered.
-the database then assigns an ID number to this document. I am able to connect to the database with SOAPUI(with JDBC Request) and I’ve been able to query the information within SOAPUI with sql_statement.
-but this ID number is needed in my next TestStep.

*Here is the heart of the issue:
- I would like to write this ID number from my Oracle sql developer(database/table) or from SOAPUI-JDBC Request into my text file(properties files).

-Or can this be done with “Property Transfers” if so how?(since I am transferring properties from a JDBC request and not a normal output <response>)

1)What are the Pre-Steps(ie, what do I need to install and/or what preparations is needed, before I start thinking about writing the data to my text file(properties sheet). )

2)what are the steps and/or codes that are needed to write the data from JDBC Request or Oracle sql Developer into my text file.

I have seen example where the code (groovy script) can read information from a .csv and/or .txt but my problem seem to be the other way around, I need to write data to a text from SOAPUI(JDBC Request) or Oracle sql Developer.

Can someone please help with this problem, or direct me to link(s) where I can find these information.

Thank you, to all for their assistance and any help will be greatly appreciated.
Sincerely.
  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Hi,

    You could use a JDBC request, and then access the response using Groovy, or you could actually implement the JDBC request within a Groovy step iteself. There's various bits on the net, but to summarise (and I'm afraid I'm tapping this out quick, so forgive me, as it's untested/not checked for accuracy)....

    1) JDBC Query using Groovy
    Not for Oracle, but an example: http://stackoverflow.com/questions/4791 ... ovy-script
    For Oracle... have a read of: viewtopic.php?f=2&t=3962

    2) Writing to a file using Groovy
    // After having retrieved a given value from SQL (or any other value)
    // Let's just hold it in a var for the moment.
    def myID = "12345";

    // write to log, just for fun...
    log.info myID;

    // Create a text file
    def outputFile = new File("C:\\myValues.txt")

    // Write value to file
    outputFile.write(myID)


    Hope this at least gives you some basic pointers.

    Kind regards,
    Tim
  • Hi Tim,

    Thanks for the super quick response. (I didn’t expect an answer back on the same day.)

    I’ll definitely try out the your suggestion. I still have some questions.

    1)I could retrieve data within my JDBC step. The statement “def myID = “12345” ”, it look as if I need to manually define this in my script step, is this correct?

    2)I have created an output file at a location already. Do I still need to use the
    “def outputFile = new File("C:\\myValues.txt")”? or is this statement use to tell SOAPUI where my file is?

    Thanks again, I hope you don’t mind if I come back with more questions later.

    Sincerely.