Unload dynamic data using JDBC into a file

Hi,
I have to download the result of a dynamic SELECT query into a file.
The query will be provided at runtime. So I am unsure of the number of columns and the data types of the columns.
Also I am unable to use io on the returned resultset object.
So basically i have to persist the data from the resultset object into a file.
Any hints
Thanks in advance

Also I am unable to use io on the returned resultset object.What do you mean by this?
See the JDBC tutorial: http://java.sun.com/docs/books/tutorial/jdbc/index.html
and the file I/O tutorial: http://java.sun.com/docs/books/tutorial/essential/io/index.html

Similar Messages

  • DISPLAY SPATIAL DATA USING JDBC ON A JAVA FRAME

    I am trying to set up some spatial data and need help in getting some sample
    code for displaying the data on a Java Frame using JDBC.
    The shapes I am setting up are simple polygons, lines, circles. I was going
    through the samples in the demo directory under $ORACLE_HOME/md/demo/examples, but could not find any JDBC
    I would really appreciate if you can point me towards some sample code and any other spatial resources.
    Madhukar

    Here you go. It uses JDBC to fetch geoms, convert them into Java JGeometry objects, which then create Java2D shapes (these are functions of the public sdoapi.jar library). It then uses some class in the sdovis.jar library (the rendering engine of MapViewer) to setup the necessary viewport transform. If you know how to setup the viewport transform, then you dont even need sdovis. sdovis.jar is found in an deployed MapViewer's WEB-INF/lib directory. Or you can extract it from the mapviewer.ear's web.war file.
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.sql.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import oracle.jdbc.OracleDriver;
    import oracle.sdovis.*;
    import oracle.sdovis.style.*;
    import oracle.sdovis.util.*;
    import oracle.spatial.geometry.JGeometry;
    import oracle.sql.STRUCT;
    * A very simple program that shows stuff from db in a JFrame
    * <p>
    public class tilsvgui2 extends JFrame
      final static int mapWidth  = 640;
      final static int mapHeight = 480;
      static JSDOGeometry geom = null;
      public tilsvgui2()
        setSize(mapWidth+40, mapHeight+40);
                    setVisible(true);
        this.addWindowListener(new java.awt.event.WindowAdapter() {
          public void windowClosing(WindowEvent e) { System.exit(0); }
            public void paint(Graphics g)
                    super.paint(g);
        int w = this.getWidth(), h = this.getHeight();
        Insets inset = this.getInsets();
        double[] mbr = geom.getMBR();
        //from sdovis; it will setup the viewport transform
        XFViewPort xfp = new XFViewPort();
        xfp.setDeviceView(inset.left, inset.top, w-inset.left-inset.right-1, h-inset.top-inset.bottom-1);
        xfp.setDataView(mbr[0], mbr[1], mbr[2], mbr[3]);
        AffineTransform af = xfp.getAffineTransform();    //get the viewport transform
        Shape shp = geom.createShape(af);    //create a proper shape that fits the viewport
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.red);
        g2.drawRect(inset.left, inset.top, w-inset.left-inset.right-1, h-inset.top-inset.bottom-1);
        //draw the shape itself
        g2.setColor(Color.blue);
        g2.draw(shp);
      public static void getStuff() throws Exception
        System.out.println("Loading geometry...");
        Connection conn = getConnection("mapsrus.us.oracle.com", "1521", "orcl", "scott", "tiger");
        Statement  stmt = conn.createStatement();
        ResultSet  rset = stmt.executeQuery("select geom, totpop from counties where county='Merrimack' and state_abrv='NH'");
        while(rset.next())
          STRUCT st = (STRUCT) rset.getObject(1);
          geom = JSDOGeometry.loadFromDB(st);
          int population = rset.getInt(2);
          break; //displaying only the first geometry
        rset.close();
        stmt.close();
        conn.close();
      private static Connection getConnection(String host,
                                              String port,
                                              String sid,
                                              String username,
                                              String password)
        throws SQLException
        String thinConn = "jdbc:oracle:thin:@"+host+":"+port+":"+sid;
        Driver d = new OracleDriver();
        Connection conn = DriverManager.getConnection(thinConn,username,password);
        conn.setAutoCommit(false);
        return conn;
      public static void main(String[] args)
        try{
          getStuff();
        }catch(Exception e)
          e.printStackTrace(System.err);
        new tilsvgui2();
    }

  • How can I import data using .dmp into the table which has more columns then in import

    I am building the history for warehouse purpose on Oracle 8i database and want to use the old import (.dmp) files (from oracle 7.3.4) to import data but the underlying table is having few more columns which are not in my old DMP file .. how can I import the data into these altered tables while using the same *.imp files .
    Any solutions ?

    That is the most obvious solution .. but think of the case when my operational database which is the source of my data is undergoing changes every quarter i.e after every 3 months there are some changes on underlying table structures which means structures of my import files will always be different after evry quarter .. you can imagine the number of temporary import structures I need to create .. can't there be a solution wherein I can write an SQL over the import file to read the data in required format ..

  • Writing CLOB data using UTL_FILE to several files by settingmaxrows in loop

    Hey Gurus,
    I have a procedure that creates a CLOB document (in the form of a table in oracle 9i). I need to now write this large CLOB data (with some 270,000 rows) into several files, setting the row max at 1000. So essentially ther would be some sort of loop construct and substr process that creates a file after looping through 1000 rows and then continues the count and creates a another file until all 270 xml files are created. Simple enough right...lol? Well I've tried doing this and haven't gotten anywhere. My pl/sql coding skills are too elementary I am guessing. I've only been doing this for about three months and could use the assistance of a more experienced person here.
    Here are the particulars...
    CLOB doc is a table in my Oracle 9i application named "XML_CLOB"
    Directory name to write output to "DIR_PATH"
    DIRECTORY PATH is "\app\cdg\cov"
    Regards,
    Chris

    the xmldata itself in the CLOB would look like this for one row.
    <macess_exp_import_export_file><file_header><file_information></file_information></file_header><items><documents><document><external_reference></external_reference><processing_instructions><update>Date of Service</update></processing_instructions><filing_instructions><folder_ids><folder id="UNKNOWN" folder_type_id="19"></folder></folder_ids></filing_instructions><document_header><document_type id="27"></document_type><document_id>CUE0000179</document_id><document_description>CUE0000179</document_description><document_date name="Date of Service">1900-01-01</document_date><document_properties></document_properties></document_header><document_data><internal_file><document_file_path>\\adam\GiftSystems\Huron\TIFS\066\CUE0000179.tif</document_file_path><document_extension>TIF</document_extension></internal_file></document_data></document></documents></items></macess_exp_import_export_file>

  • How to get sql query data and write into csv file?

    I am writing to seek help, in how can I create bat. script which can execute the following logic:
    connection to the database
    run sql query
    create CSV file
    output query data, into CSV file
    save the CSV file
    osql
    -S 84.18.111.111
    -U adw
    -P rem
    -i "c:\query.sql"
    send ""
    sed -e 's/,\s\+/,/g' MCI_04Dec2014.csv > localNoSpaces.csv
    -o "c:\MCI_04Dec2014.csv"
    This what i have so far, and I am little struggling with the logic after creating CSV file. I am unable to get the above script to work, please advice further, where I may be going wrong. 
    Can you create if statement logic within window's script, to check for null parameters or data feeds?
    Any hints would be most appreciated. 

    Thank you for your reply. 
    Apology for posting the code irrelevant to the forum, as I am still novice scripting user.  
    My goal is to create window's script which can compute the above logic and send the final output file (csv), to FTP folder. 
    Can this logic be implemented via bat. script, if so, is there a example or tutorial i could follow, in order to achieve my task. 
    Any help would be much appreciated. 

  • Problem in Uploading Data using a Tab Separated File?

    Hi All,
    I am trying to upload a file which tab separated containing customer and bank details and my file structure somewhat in the following manner.
    10     21169     abcde     xyz     kdHDHLk     gdh     ghgah  (Customer Details)
    20     21169     DE     20050000     01122334  (bank details for customer 21169)
    20     21169     DE     23022200     1122334455
    (bank details for customer 21169)
    20     21169     DE     23984899     223344556    (bank details).
    But when I am trying to intial upload the details to an internal table using GUI_upload FM and display to check if it is loading correctly or not it is not giving me any o/p.
    I am copying the code which I am trying to execute. Please tell me what way I need to modify the code so that it executes correctly.
    parameters: p_file type rlgrap-filename.
    data: begin of wa_file,
          text(256) type c,
          end of wa_file.
    data: it_file like table of wa_file.
    types: begin of ty_kna1,
           kunnr type kunnr,
           name1 type name1,
           sortl type sortl,
           stras type stras,
           ort01 type ort01,
           land1 type land1,
           spras type spras,
           end of ty_kna1.
    data: it_kna1 type standard table of ty_kna1,
          wa_kna1 type ty_kna1.
    types: begin of ty_knbk,
           kunnr type kunnr,
           banks type knbk-banks,
           bankl type knbk-bankl,
           bankn type knbk-bankn,
           end of ty_knbk.
    data: it_knbk type standard table of ty_knbk,
          wa_knbk type ty_knbk.
    data: v_id(2).
    At Selection-Screen on Value-Request for p_file.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
       PROGRAM_NAME        = SYST-CPROG
       DYNPRO_NUMBER       = SYST-DYNNR
    *   FIELD_NAME          = ' '
    IMPORTING
       FILE_NAME           = p_file
    Start-of-Selection.
    data: p_file1 type string.
          p_file1 = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = p_file1
       FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = 'X'
    *   HEADER_LENGTH                 = 0
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    * IMPORTING
    *   FILELENGTH                    =
    *   HEADER                        =
      TABLES
        DATA_TAB                      = it_file
    * EXCEPTIONS
    *   FILE_OPEN_ERROR               = 1
    *   FILE_READ_ERROR               = 2
    *   NO_BATCH                      = 3
    *   GUI_REFUSE_FILETRANSFER       = 4
    *   INVALID_TYPE                  = 5
    *   NO_AUTHORITY                  = 6
    *   UNKNOWN_ERROR                 = 7
    *   BAD_DATA_FORMAT               = 8
    *   HEADER_NOT_ALLOWED            = 9
    *   SEPARATOR_NOT_ALLOWED         = 10
    *   HEADER_TOO_LONG               = 11
    *   UNKNOWN_DP_ERROR              = 12
    *   ACCESS_DENIED                 = 13
    *   DP_OUT_OF_MEMORY              = 14
    *   DISK_FULL                     = 15
    *   DP_TIMEOUT                    = 16
    *   OTHERS                        = 17
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    constants: c_tab type X value '09'.
    loop at it_file into wa_file.
    if wa_file+0(2) = '10'.
    split wa_file at 'c_tab'
              into v_id
                   wa_kna1-kunnr
                   wa_kna1-name1
                   wa_kna1-sortl
                   wa_kna1-stras
                   wa_kna1-ort01
                   wa_kna1-land1
                   wa_kna1-spras.
    append wa_kna1 to it_kna1.
    elseif wa_file+0(2) = '20'.
    split wa_file at 'c_tab'
           into v_id
                wa_knbk-kunnr
                wa_knbk-banks
                 wa_knbk-bankl
                 wa_knbk-bankn.
    append wa_knbk to it_knbk.
    endif.
    endloop.
    write:/ 'Customer Master General Data'.
    uline.
    loop at it_kna1 into wa_kna1.
    write:/ wa_kna1-kunnr,
             wa_kna1-name1,
                   wa_kna1-sortl,
                   wa_kna1-stras,
                   wa_kna1-ort01,
                   wa_kna1-land1,
                   wa_kna1-spras.
    endloop.
    clear wa_kna1.
    skip 2.
    write:/ 'Customer Master Bank Data'.
    uline.
    loop at it_knbk into wa_knbk.
    write:/ wa_knbk-kunnr,
             wa_knbk-banks,
             wa_knbk-bankl,
             wa_knbk-bankn.
    endloop.
    clear wa_knbk.
    Regards,
    MD

    Declare Class cl_abap_char_utilities
    Use File type as 'DBF'
    Has_field_seperator = w_tab in FM GUI_UPLOAD
    DATA: w_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
        CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
        BIN_FILESIZE                    =
          filename                        = w_file
       filetype                        = 'DBF'
        append                          = ' '
       write_field_separator           = w_tab
        TABLES
          data_tab                        = it_extractchar
       fieldnames                      = it_header
    EXCEPTIONS
       file_write_error                = 1
       no_batch                        = 2
       gui_refuse_filetransfer         = 3
       OTHERS                          = 22

  • Retrive Japanese data and store into a file

    Hi,
    I have a table which contains japanese data. My database charset is AL32UTF8. I am able to insert japanse data into oracle table also I am able to view inserted data into oracle table using sql*plus.
    I wrote a java program to write a file with table stored data. To fetch that data I am using sql query. When I use ojdbc14.jar of version 9.0.2.0.0. Then I am able to write japanse data file but when I use ojdbc14.jar of version 10.2.0.3.0. Then I found junked data into data file.
    Please help me out to solve this problem.

    The BIP Bursting APIs allow you to hook in code, in which you could achieve what you mention - but would require programming it!
    Regards,
    Gareth

  • Capturing data using write to measurement file for encoder

    hello dear,
    can anyone help to check with my encoder to measure data?
    i have connect the write to measurement file but when i open the .txt file,
    no result appear, thanks so much for your help
    Solved!
    Go to Solution.
    Attachments:
    encoder capture.vi ‏180 KB

    well, I have never used that method to write data to a file, but if you double click on your write the write LabVIEW measurement file object and look at the configuration you have selected save to a series of files.  Is that what you wanted, or did you just want one file?
    Jim
    Jim
    LV 2013

  • Initialize a date using eCATT and a file

    We are trying to clear the values in a date field (MBEW-ZKDAT), i.e. we're trying to update the field from some date to the initial value.
    We have an eCATT that has been working fine when there is some value in the date field. But when we try to put any other value (00/00/0000, 00000000 or just leave it blank) in the file, we're getting 'Invalid date' error.
    I've looked in FAQ, SAP Help, but can't find any useful information on this. Does anyone know what we need to enter in the date field to make it blank (=initialize)?
    Thank you.

    Hello Jelena
    Normally &CLEAR does this job.
    [Special Variables (eCATT Tutorial)|http://help.sap.com/saphelp_nw04/helpdata/EN/3d/72cd3bb961766de10000000a11402f/content.htm]
    Regards
      Uwe

  • Not able to fetch updated data using jdbc and oracle 10g

    Whenever i m updating the data and fetching the same record after updating i m not able to get the fresh/new updated data , old record is fetched every time, but when i checked in database the record gets updated successfully , even if i fire the query two times after 10 seconds using Thread.sleep even then problem persist.
    Please help me out!!!!!!!!
    Implementation has been stucked up!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :(

    Well its okWhat is OK? Your stuff working now?
    i m doing the same thing Apparently not.
    please go thru the below code fragment:
    code for Update :::
    DataAccessBean1 partsHistoryDataAccessBean = new
    DataAccessBean1(context);
    partsHistoryDataAccessBean.setData(data);
    partsHistoryDataAccessBean.update();
    After Updating i m forwading it to the other servletForwarding what? Why do you need another servlet? Just do the query, put the new data into the response object, and return.
    According to your assumption i should get the updated
    data on the other screen but Nope, you don't understand what I'm saying.
    %

  • Reading CLOB data using jdbc thin driver

    Hi,
    When I try reading data for a CLOB column using thin jdbc driver, I get the following error message
    "Exception: ORA-06550: line 1, column 22:
    PLS-00302: component 'GETCHUNKSIZE' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored".
    This error message is displayed when the call is made to get the character stream from the Clob object.
    Do I need to any server side setup before I can access CLOB data from the database?
    thanks.
    Puru Balakrishnan

    I updated to the latest jdbc drivers, 816classes12b.zip, and the problem went away.
    null

  • Assigning an exact time to poll data using JDBC Sender?

    Hi,
    Can I set an exact time to poll data from DB table?
    I means, I want to poll data every 6 pm.
    But I cannot find fields to set starting time.
    There exist only poll interval fields in JDBC Sender.
    Regards,
    hiyoung.

    Hi,
    This might help you out.
    To run a scenario exactly once in a specific time every day    / schedule a adapter
    Note:You will need to have the authorizations of the user group SAP_XI_ADMINISTRATOR with the role modify.
    Go to Runtime Workbench -> Component Monitoring -> Communication Channel Monitoring
    Locate the link Availability Time Planning on the top right corner of your Communication Channel Monitoring page.
    In your case, the requirement is to schedule the Sender file adapter daily once at 12:00 at midnight.
    In Availability Time Planning, choose the Availability time as daily and say create.
    Provide the details like the time 12:00
    Then select the communication channel , goto the Communication Channels tab and filter and add the respective channel (File Sender).
    Once all the above has been done 'Save' the changes.
    <b>Cheers
    *RAJ*
    *REWARD POINTS IF FOUND USEFULL*</b>

  • How do I insert the Date in time into my file?

    VI is Attached?
    Attachments:
    Temperature_Testing_Modified.vi ‏71 KB

    Give the operator a front panel control to enter the Save Interval. Use a shift register on your While loop (initialized to a Double = 0) to hold the Last Time Saved. In your loop, call the Get Date/Time in Seconds function (from the Time & Dialog palette). If the current time - Save Interval > Last Time Saved, save the data and update the Last Time Saved.
    See the attached LabView 6.1 example.
    Attachments:
    Save_at_intervals.vi ‏23 KB

  • Need a suggestion in getting data using JDBC

    Hi,
    There is a Emp table in database.
         And there is a corresponding Value Object(Contains getter and setter
         methods for columns of Emp table).
         If i fire a query to Emp, then the records will be stored in ResultSet.
         I am passing the table as a paremeter to a method.(so that no. of columns
         should vary)
         Now my problem is how can i initialize each column value getting from
         ResultSet into corresponding VO setter method.

    Like this probably: vo.setX(rs.getInt("X"));

  • Need suggestion in getting data using JDBC

    Hi all need suggestion,
         i had a VO corresponding to database table.
         when i am try to get the records from that table,
         how can i initialize the particular column value to the
         corresponding VO setter method.
         please do the needful.

    Hello inform2csr,
    Your question is not so clear.
    Can you be more precise?
    What is VO?

Maybe you are looking for

  • Trouble compiling OpenSceneGraph

    Hi there! In order to compile the latest FlightGear, I need to compile OpenSceneGraph. I know, it's in the repos, but that's how it goes. Now it always stops compiling after complaining during configuration: CMake Warning at /usr/share/cmake-2.8/Modu

  • How to set the View instance and view  attribute to lov field ?

    Hi I created lov and textfield programatically. I want to set the viewattribute and view instance to that items(lovbean, texfieldbean). How to set programatically? Thanks in Advance Awadesh

  • Setting up start date for automatic backup

    IS there instructions on how to set up automatic back up setting start date WD Element 3 tb external hard drive. I have previous backups on another external drive and do not want to duplicate what I already have backed up...any help would be apprecia

  • How to install Airport_Utility 5.6?

    Hi I have airport extreme its utility says"This version of AirPort Utility doesn't support this base station. Use AirPort Utility 5.6 to configure or manage this base station. AirPort Utility 5.6 is available at AirPort Service and Support."

  • Merging Log Files with same name

    Hello, I have log files with same name 00000000.jdb (because created at different machines). I would like to merge data stored in these two files. I tried below approaches which do not work: 1. rename one of the files -> doesn't work as file header h