Writing result set to .csv file

All,
I am writing a result set(date and a message as a string)
if(rs!= null){
                date = new java.util.Date();
                String logDate = sdf.format(date);
                File log = new File(logDate+".csv");
                writer = new BufferedWriter(new FileWriter(log));
           // 5) Move to first record (and then next) record.
           while(rs.next())
              writer.write(rs.getString(1) + "," + rs.getString(2) + "\n");
                rowCount++;
           }Eaxmple:
1. 2008-03-31 error during
The problem is when I write this to a .csv file, when opened with excel, the date appears as
If I right click the column, and select format, I can format the date properly, but I don't want to do this.
Any suggestions?
M

##### is what Excel usually displays when it can't display the entire cell contents in the width of the column. Try expanding the column in Excel and see if the date appears.

Similar Messages

  • Exporting query result set into CSV file using Forms

    Hi ,
    My requirement is
    -> I need to create a form where I have a Multi line text box and two button.
    -> When I enter a query in text box and click on Execute button, It should execute a select query.
    -> After execution, Result set needs to be exported into an Excel file.
    Please give a hint how to do this????
    Thanks,
    maddy

    as you are using text item to write SQL query by the user
    so for that you need to use the exec_sql package to parse the text items query and get definitions and values of the columns being
    resulted in the result set of the query.
    once your query is execute to the desired connection then you need to use fetch the result to the CSV file by use of the TEXT_io package
    which will open the text file with .csv extension and you have to pass the each line to that text file with comma separated values as "ss","rr" etc.
    or you can use the ole2 package to call the excel application and then fetch the data of exe_sql query to that.

  • Writing the Result set to a file!

    Hello ...java gurus.. pls i want to write the contents of my result set to a file ...i have tried it but when i open the files it contains jargons any other way?
    thanks.

    Just get the results as strings, ints or whatever you want and write them. If you want, store results in vectors, hashes... and write the file after closing connections.

  • How to Compare 2 CSV file and store the result to 3rd csv file using PowerShell script?

    I want to do the below task using powershell script only.
    I have 2 csv files and I want to compare those two files and I want to store the comparision result to 3rd csv file. Please look at the follwingsnap:
    This image is csv file only. 
    Could you please any one help me.
    Thanks in advance.
    By
    A Path finder 
    JoSwa
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"
    Best Online Journal

    Not certain this is what you're after, but this :
    #import the contents of both csv files
    $dbexcel=import-csv c:\dbexcel.csv
    $liveexcel=import-csv C:\liveexcel.csv
    #prepare the output csv and create the headers
    $outputexcel="c:\outputexcel.csv"
    $outputline="Name,Connection Status,Version,DbExcel,LiveExcel"
    $outputline | out-file $outputexcel
    #Loop through each record based on the number of records (assuming equal number in both files)
    for ($i=0; $i -le $dbexcel.Length-1;$i++)
    # Assign the yes / null values to equal the word equivalent
    if ($dbexcel.isavail[$i] -eq "yes") {$dbavail="Available"} else {$dbavail="Unavailable"}
    if ($liveexcel.isavail[$i] -eq "yes") {$liveavail="Available"} else {$liveavail="Unavailable"}
    #create the live of csv content from the two input csv files
    $outputline=$dbexcel.name[$i] + "," + $liveexcel.'connection status'[$i] + "," + $dbexcel.version[$i] + "," + $dbavail + "," + $liveavail
    #output that line to the csv file
    $outputline | out-file $outputexcel -Append
    should do what you're looking for, or give you enough to edit it to your exact need.
    I've assumed that the dbexcel.csv and liveexcel.csv files live in the root of c:\ for this, that they include the header information, and that the outputexcel.csv file will be saved to the same place (including headers).

  • How to call a SP with dynamic columns and output results into a .csv file via SSIS

    hi Folks, I have a challenging question here. I've created a SP called dbo.ResultsWithDynamicColumns and take one parameter of CONVERT(DATE,GETDATE()), the uniqueness of this SP is that the result does not have fixed columns as it's based on sales from previous
    days. For example, Previous day, customers have purchased 20 products but today , 30 products have been purchased.
    Right now, on SSMS, I am able to execute this SP when supplying  a parameter.  What I want to achieve here is to automate this process and send the result as a .csv file and SFTP to a server. 
    SFTP part is kinda easy as I can call WinSCP with proper script to handle it.  How to export the result of a dynamic SP to a .CSV file? 
    I've tried
    EXEC xp_cmdshell ' BCP " EXEC xxxx.[dbo].[ResultsWithDynamicColumns ]  @dateFrom = ''2014-01-21''"   queryout  "c:\path\xxxx.dat" -T -c'
    SSMS gives the following error as Error = [Microsoft][SQL Server Native Client 10.0]BCP host-files must contain at least one column
    any ideas?
    thanks
    Hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Hey Jakub, thanks and I did see the #temp table issue in our 2008R2.  I finally figured it out in a different way... I manage to modify this dynamic SP to output results into
    a physical table. This table will be dropped and recreated everytime when SP gets executed... After that, I used a SSIS pkg to output this table
    to a file destination which is .csv.  
     The downside is that if this table structure ever gets changed, this SSIS pkg will fail or not fully reflecting the whole table. However, this won't happen often
    and I can live with that at this moment. 
    Thanks
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

  • Setting up csv files as a data source for Hyperion intelligence explorer on Windows 7

    Hi. wondering anyone can point me to a resource or supply me with step son how to Set up csv files as a data source for Hyperion intelligence explorer on Windows 7?
    I used to be able to do it in WXP, but it seems thing shave really changed with W7..... Absolutely desperate... All and any help welcome.....

    Hi
    Can you please try setting up full persmission in the security properties for everyone on the wsconfig folder C:\ColdFusion10\config\wsconfig  and restart ColdFusion Server.
    Swaraj

  • How to - extract query result set in CSV and make multiple files if result set is huge.

    I have a query which returns millions of rows. I need to extract those rows in CSV files. Having said that i want to keep these files under a limit of 500 MB . Result set can be distributed among multiples files but each file can not be > 500 MB in size.
    How to achieve this?

    You may use this standard! procedure from Blushadow and produce something useful for your need. https://community.oracle.com/message/6499123#6499123

  • Correlation Between several Different Arrays & Saving Results Into a.CSV file

    Hello Everyone!
    I have 3 arrays from which I initialize a .CSV file when I run my VI (
    as you can see in the example file.)( I use data from other arrays as
    well but it is not important )
    The First array "customer Number" can be from 0 - 15
    The second array "Customer Present" is a Boolean.
    The Third array will contain some fix values like " milk, meat, clothing....." it will have 14 different categories.
    The Fifth array will contain the quantity of the products from each category from the previous array.
    My job is to add in my initialized .CSV file the values from the 4th and 5th array but only for the customers that are present.
    The result should look something like the second part of the doc I give( which sadly, I created by hand)
    If no customer has bought something from a category it should not be mentioned.
    Also it would be nice for me if I separated the file for each customer ( create 16 different files )
    I hope someone has some idea, because I don't.
    I figured out that I should have the bool array into a case structure and if the customer is present then........
    Thank you in advance!
    Attachments:
    Initilized&Data.doc ‏42 KB
    Initialize.GIF ‏21 KB

    I don't understand where correlation fits into this...
    It seems to me that you're trying to write out a file from the values on front panel controls, rather than the other way around, as Bernd was suggesting. I see no actual read functions in your screenshot. What does your front panel look like? Can you post the VI and give a brief description on how it's supposed to be used? You seem to have some front panel arrays that you're indexing out. For this you should be using auto-indexing rather than using a fixed constant. Also, the local variables are completely unnecessary - what I see is text-based programming.

  • Export query results to a CSV file

    Hi,
    My requirement is I need to export the results of a query to a CSV file. Can anyone please suggest a way to include the column names also in the CSV file?
    Thanks in advance.
    Annie

    Following code is from asktom. I have modified to include column heading. This will get your desired CSV file for a given query.
    create or replace function  dump_csv( p_query     in varchar2,
                                          p_separator in varchar2
                                                        default ',',
                                          p_dir       in varchar2 ,
                                          p_filename  in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(2000);
        l_status        integer;
        l_colCnt        number default 0;
        l_separator     varchar2(10) default '';
        l_cnt           number default 0;
         l_colDesc          dbms_sql.DESC_TAB;
    begin
        l_output := utl_file.fopen( p_dir, p_filename, 'w' );
        dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
        for i in 1 .. 255 loop
            begin
                dbms_sql.define_column( l_theCursor, i,
                                        l_columnValue, 2000 );
                l_colCnt := i;
            exception
                when others then
                    if ( sqlcode = -1007 ) then exit;
                    else
                        raise;
                    end if;
            end;
        end loop;
        dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
        l_status := dbms_sql.execute(l_theCursor);
         dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
         l_separator := '';
         for lColCnt in 1..l_colCnt
         loop          
                utl_file.put( l_output, l_separator ||  '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
                   l_separator := p_separator;
         end loop;
         utl_file.new_line( l_output );
        loop
            exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
            l_separator := '';
            for i in 1 .. l_colCnt loop
                dbms_sql.column_value( l_theCursor, i,
                                       l_columnValue );
                utl_file.put( l_output, l_separator ||  '"' ||
                                        l_columnValue || '"');
                l_separator := p_separator;
            end loop;
            utl_file.new_line( l_output );
            l_cnt := l_cnt+1;
        end loop;
        dbms_sql.close_cursor(l_theCursor);
        utl_file.fclose( l_output );
        return l_cnt;
    end dump_csv;The original link is below.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:95212348059
    Thanks,
    Karthick.

  • Select Query Results to a .csv file????

    Hello All,
    I have a question in Oracle, if anyone knows how to do this. Please help me.
    How can I get the results of select query in Oracle loaded into a Excel file (.csv) file.
    Thanks in Advance,
    Sarada.

    Hi Sarada,
    as a csv is nothing more than a list of Comma Separated Values your best shot is to simply read do this with your values. read each value in an iteration add them to a string / stringbuffer and add a "," between them. When you read then next line in the ResultSet you just add a carriage return to the end. Depending on what format you want your csv list in.
    After you written all of this into a String you write this out to a file (unless you want to do it slower and write them line by line whenever you read them).
    Hope this helps,
    Kalle

  • Exporting query results into a csv file using arabic and hebrew chars

    Hi,
    iv'e encountered a problem, using plsql to export a query into a csv file.. the arabic turns into question mark. Do you have any idea why?

    Usually this indicates a mismatch between client and database character set.
    How do you export this query?
    What is your database version?
    What is your client OS?
    T.

  • Overwriting result sets in a file

    Hello, I am querying a database and putting the results into a ResultSets. When the user clicks a button the results are written to an Excel worksheet. However, each time you click the button or write to the worksheet, the ResultSet is appended to the previous one. Is there a way to overwrite??? Thank you in advance.

    here is the method I created to insert a result set into MS Excel
    public void output_vehicleInfo(ResultSet rset)
    try{
    prepared_statement = con.prepareStatement("insert into \"VehicleInfo$\" (BumperNumber, Noun, Section) values (?, ? ?)");
    while(rset.next())
    prepared_statement.setString(1,rset.getString(1));
    prepared_statement.setString(2,rset.getString(2));
    prepared_statement.setString(3,rset.getString(3));
    prepared_statement.execute();
    //catch clause
    The code works; however, it doesn't insert at the beginning of the table. It inserts after the last record. I want to overwrite all data with the insert.

  • Writing data from a CSV file in to table

    Hi All,
    I have a CSV (Comma Separated Values) file and i want to write its data in to the table.
    How can i get data from a CSV file.

    As Karthick suggested, you can use External Tables or Sql Loader functionality
    You can check this link for example on Sql Loader http://surachartopun.com/2007/10/example-sql-loader-some-data-into.html

  • Unable to save the webi report results in CSV file in XIR2 environment

    Hi Team,    
    We have one WebI report in BOXIR2 version and it fetching nearly 76+ records in the report. The report is running fine without any issues and when i am trying to export the results into CSV file we are getting the error msg (Maximum Binary file size exceeded WIS30271). The file size is more than 80MB and hence it throwing this error. I have checked the Maximun Binary File size that is set in CMC and it is set to 80MB.
    When i ran the same query in the database and exporting the results in to csv file the file size is under 80MB. I would like to know the reason why there is a difference in the file size when running the query manually in database and exporting in to csv file and to export the results set in to csv through business objects.

    Below are the possible causes to get this error message:
    1] When a large Web Intelligence report is exported to CSV format, we get error: Max Binary file size limit exceeded. The document is too large to be processed by the server. Error WIS 30271
    Cause
    This error message appears because BusinessObjects Enterprise allows documents to be saved with the limit specified for Web Intelligence Report server settings in the Central Management Console(CMC).
    To resolve the error follow the below steps:
    - Login to Central Management Console (CMC) using BusinessObjects Enterprise "Administrator".
    - Navigate to "Home >> Servers".
    - Click on "Web Intelligence Report Server" to open its properties.
    - Increase the "Maximum Binary File Size"(Default value=50 MBytes; Maximum value = 65535 MBytes).
    - Click on "Apply" and then on "Update".
    - Allow the Web Intelligence server to restart.
    2] In Web Intelligence, when attempting to save a report to Excel or Portable Document Format  (PDF), the following error message appears:
    "Max binary file size limit exceeded. The document is too large to be processed by the server. Contact your database administrator. (Error: WIS 30271)".
    Cause:
    This error message appears because Business Objects Enterprise allows documents to be saved up to the limit set for Web Intelligence Report Server in the Central Management Console (CMC).  The default file size limit is 50 megabytes for binary file types like PDF and Excel.
    To resolve this error message, you will need to increase the Max Binary file size value.
    1.      Open the CMC.
    2.      Browse to Servers
    3.      Click on your Web Intelligence Report Server.
    4.      On the Properties page, increase the Maximum Binary File Size.
    5.      Apply the setting and allow the Web Intelligence Report Server to restart.
    Increasing these values too high could impact Web Intelligence performance when users attempt to save excessively large files.
    Hope this helps.

  • Transfer data from Result Set (Execute SQL Task) into Flat File

    Hi to all,
    My problem is this:
     -) I have a stored procedure which use a temporary table in join with another "real" table in select statement. In particular the stored procedure look like this:
    create table #tmp
    col1 varchar(20),
    col2 varchar(50)
    --PUT SOME VALUE IN #TMP
    insert into #tmp
    values ('abc','xyz')
    --SELECT SOME VALUE
    select rt.*
    from realTable rt, #tmp
    where rt.col1 = #tmp.col1
    -) I cannot modify the stored procedure because I'm not admin of database.
    -) I HAVE THE REQUIREMENT OF TRANSFER DATA OF SELECT STATEMENT OF SOTRED PROCEDURE INTO FLAT FILE
    -) THE PROBLEM is that if I use an OLEDB source Task within a Data Flow Task I'm not be able of mapping column from OLEDB source to flat file destination. The reason for this, is that in the "Column page" of OLEDB source task, SSIS do not retrieves
    any column when we using a temporary table. The reason for this, is that SSIS is not be able to retrieve metadata related to temporary table. 
    -) One possible solution to this problem is to use an Execute SQL Task to invoke the stored procedure, store the result returned from stored procedure in a Result Set through a Object type user variable.
    -) The problem now is: How to transfer data from result set to flat file?
    -) Reading here on this forum the solution look be like to use a Script task to transfer data from result set to flat file.
    QUESTIONS: How to transfer data from result set to flat file using a script task?? (I'm not an expert of vb .net) Is it really possible?? P.S.: The number of row returned of stored procedure is very high!
    thanks in advance.

    Hi  Visakh16<abbr
    class="affil"></abbr>
    thanks for the response.
    Your is a good Idea, but I do not have permission to use DDL statement on the database in production environment.

Maybe you are looking for