How to read a CSV file into the portal
hi all,
I want to read the content of CSV file that is avaliable in my desktop.
plz help me with suitable code
Regards
Savitha
Edited by: Savitha S R on Jun 1, 2009 8:25 AM
Please use this code for that
REPORT znkp_upload_csv line-size 400.
DATA : v_filename TYPE string.
PARAMETER : p_file LIKE rlgrap-filename DEFAULT 'C:\Documents and Settings\Administrator\Desktop\JV.csv' .
*Types for Reading CSV file
TYPES : BEGIN OF x_csv,
text(400) TYPE c,
END OF x_csv.
*Global internal table for reading CSV file
DATA : lt_csv TYPE TABLE OF x_csv.
*Global work area for reading CSV file
DATA : wa_csv LIKE LINE OF lt_csv.
v_filename = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_filename
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = lt_csv
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.
DATA : BEGIN OF item OCCURS 0 ,
t1(20) TYPE c,
t2(20) TYPE c,
t3(20) TYPE c,
t4(20) TYPE c,
t5(20) TYPE c,
t6(20) TYPE c,
t7(20) TYPE c,
t8(20) TYPE c,
END OF item.
DATA : txt(1) TYPE c. " 1-Header 2-Item
LOOP AT lt_csv into wa_csv.
split wa_csv-text at ',' into item-t1
item-t2
item-t3
item-t4
item-t5
item-t6
item-t7
item-t8.
append item.
clear item.
ENDLOOP.
Check ITEM TABLE
Regards
Naresh
Similar Messages
-
How to import an .csv file into the database?
and can we code the program in JSP to import the.csv file into the database.
It is better to use Java class to read the CSV file and store the contents in the database.
You can use JSP to upload the CSV file to the server if you want, but don't use it to perform database operations.
JSPs are good for displaying information on the front-end, and for displaying HTML forms, there are other technologies more suitable for the middle layer, back end and the database layer.
So break you application into
1) Front end - JSPs to display input html forms and to display data retrieved from the database.
2) Middle layer - Servlets and JavaBeans to interact with JSPs. The code that reads the CSV file to parse it's contents should be a Java Class in the middle layer. It makes use of Java File I/O
3) Database layer - Connects to the database using JDBC (Java Database Connectivity), and then writes to the database with SQL insert statements.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keeping the above concepts in mind, first build a simple JSP and get it to work,
then research on Google , for Java File I/O , discover how to read a file,
Then search on how to readh a CSV file using Java.
After researching you should be able to read the CSV file line by line and store each line inside a Collection.
Then research on Google, on how to write to the database using JDBC
Write a simple program that inserts something to a dummy table in the database.
Then, read the data stored in the Collection, and write insert statements for each records in the collection. -
How to read/write .CSV file into CLOB column in a table of Oracle 10g
I have a requirement which is nothing but a table has two column
create table emp_data (empid number, report clob)
Here REPORT column is CLOB data type which used to load the data from the .csv file.
The requirement here is
1) How to load data from .CSV file into CLOB column along with empid using DBMS_lob utility
2) How to read report columns which should return all the columns present in the .CSV file (dynamically because every csv file may have different number of columns) along with the primariy key empid).
eg: empid report_field1 report_field2
1 x y
Any help would be appreciated.If I understand you right, you want each row in your table to contain an emp_id and the complete text of a multi-record .csv file.
It's not clear how you relate emp_id to the appropriate file to be read. Is the emp_id stored in the csv file?
To read the file, you can use functions from [UTL_FILE|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#BABGGEDF] (as long as the file is in a directory accessible to the Oracle server):
declare
lt_report_clob CLOB;
l_max_line_length integer := 1024; -- set as high as the longest line in your file
l_infile UTL_FILE.file_type;
l_buffer varchar2(1024);
l_emp_id report_table.emp_id%type := 123; -- not clear where emp_id comes from
l_filename varchar2(200) := 'my_file_name.csv'; -- get this from somewhere
begin
-- open the file; we assume an Oracle directory has already been created
l_infile := utl_file.fopen('CSV_DIRECTORY', l_filename, 'r', l_max_line_length);
-- initialise the empty clob
dbms_lob.createtemporary(lt_report_clob, TRUE, DBMS_LOB.session);
loop
begin
utl_file.get_line(l_infile, l_buffer);
dbms_lob.append(lt_report_clob, l_buffer);
exception
when no_data_found then
exit;
end;
end loop;
insert into report_table (emp_id, report)
values (l_emp_id, lt_report_clob);
-- free the temporary lob
dbms_lob.freetemporary(lt_report_clob);
-- close the file
UTL_FILE.fclose(l_infile);
end;This simple line-by-line approach is easy to understand, and gives you an opportunity (if you want) to take each line in the file and transform it (for example, you could transform it into a nested table, or into XML). However it can be rather slow if there are many records in the csv file - the lob_append operation is not particularly efficient. I was able to improve the efficiency by caching the lines in a VARCHAR2 up to a maximum cache size, and only then appending to the LOB - see [three posts on my blog|http://preferisco.blogspot.com/search/label/lob].
There is at least one other possibility:
- you could use [DBMS_LOB.loadclobfromfile|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978]. I've not tried this before myself, but I think the procedure is described [here in the 9i docs|http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl12bfl.htm#879711]. This is likely to be faster than UTL_FILE (because it is all happening in the underlying DBMS_LOB package, possibly in a native way).
That's all for now. I haven't yet answered your question on how to report data back out of the CLOB. I would like to know how you associate employees with files; what happens if there is > 1 file per employee, etc.
HTH
Regards Nigel
Edited by: nthomas on Mar 2, 2009 11:22 AM - don't forget to fclose the file... -
How to read an excel file into the datatable in sdk code( AddonApplication)
Hi Experts,
Please let me know the code ,how to write an excel file to the datatable and based on the datatable it should write to the database table.
help would be appreciated...
Regards,
Vijay Kumar
Edited by: Haroon Rasheed on Oct 29, 2011 10:40 PMHi,
You may check: Read Excel File by Sheet then put it in Matrix
Thanks,
Gordon -
How to read a gif file into the java file?
i want to read an image(*.gif) file into my appication. can u plz help me in this?
Hi
I have made a program that display images here is the code i hope it helps
package ImageProcessing;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ImageProcessing
public static Image imRead(String imagePath)
Image im = null;
try
File imageFile = new File(imagePath);
im = ImageIO.read(imageFile);
catch(Exception e)
e.printStackTrace();
return im;
public void imWrite(Image im,String fileFormat,String imagePath) throws IOException
File outputFile = new File(imagePath);
ImageIO.write((RenderedImage) im, fileFormat, outputFile);
public static void imShow(String imagePath)
ImageObserver io = null;
JFrame frame = new JFrame();
Image im = imRead(imagePath);
ShowImage imShow = new ShowImage(im);
frame.add(imShow);
frame.setVisible(true);
frame.setTitle(imagePath);
frame.setSize(im.getWidth(io),im.getHeight(io));
frame.setResizable(false);
frame.show();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public static void main(String[] args) throws IOException
imShow("D:\\My Computer\\Images\\Cash2.gif");
package ImageProcessing;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
public class ShowImage extends Panel
Image im;
public ShowImage(Image inputIm)
im = inputIm;
public void paint(Graphics g)
g.drawImage(im, 0, 0, null);
} -
Hi Everyone,
I want to create a powershell script file
1) Check a directory and upload all termset csv files into the SharePoint local taxonomy.
2) Input paramaters - directory that containss termset csv files, Local Termstore to import to,
3) Prior to updating get a backup of the existing termstore (for rollback/recovery purposes)
4) Parameters should be passed in via XML file.
Please let me know how to do it.
Regards,
SrinivasHi,
Please check this link
http://termsetimporter.codeplex.com/
Please remember to click 'Mark as Answer' on the answer if it helps you -
How to sent importet RAW files into the cloud? The files was importet from Canon EOS via camera adapter to the iPad. The Files was stored in the folder importet. But the files does not sync with photostream.
Welcome to the Apple community.
Only photos taken on the iOS device and after photo stream was enabled will be added to photo stream. -
How to import jar & exp file into the eclipse 3.1 + jcop
hi, I am new to the javacard technology.
I have implementing applet by using eclipse 3.1 + jcop plugin.
recentlly, i got jar and exp file from someone. and I have to import given two files in the my applet.
Q1. but i don't know how to use(import) two files into the elipse.
and...
I have tried to put the export file structure in the build path, but I am still getting the same error:
Q2. "resolving constant-pool of clazz cash/ccash; failed: no such clazz cash/ccash;", what means?
anyone help me~plz!
many thanks..
lsh.
Message was edited by:
neonoble1) In the Package explorer right-click the project you want to import the jar files into.
2) Click import
3) Select Archive file in the Import dialog box and click next
4) Browse to the jar file and select it
Socx -
How do I get my file into the time line in Premiere Pro CC?
How do I get my file into the time line in Premiere Pro CC? I am use to Premier Pro CS6 and unfortunately my labtop took a crash and I lost all of my adobe products. I wanted to check out a trial version and I cannot seem to find one for CS6! Please Help Me! My project is due tonight!!!!!
Hi Aneumann,
Welcome to the Forums.
You have to just right click on the clip imported, in the project panel and select new sequence from clip. You can also go to file menu>new>sequence and create a sequence and then drag the clips after importing them , into the timeline.
Regards,
Vinay -
How to covert a CSV file into a file of spreadsheet format(staroffice)?
Hello everybody,
I want to create a java that can convert CSV file into spreadsheet. But i dont have any idea how to create a Spreadsheet (i just know it have a Binary File format).
So anyone can give me some reference or program sample, some advises ????
Pls help
thxHi
set the content type as given below and PrintWriter class to write into excel sheet
response.setContentType("application/x-msexcel");
response.setHeader("Content-Disposition", "attachment; filename=" + "abc Download" + ".xls"); -
After creating a new user account, how do I move my files into the new user?
I have an issue where my 'Desktop/Screensaver' prefs seem to be corrupt somehow. When I click on that icon in System Preferences, it stalls and I get the spinning ball, thus resulting in a force quit. After reading a Mac Format magazine where someone wrote in with a similar issue, they said to trash various prefs (did that and made no difference) and if that didn't work, try creating a New User account (therefore creating brand new system prefs) and move your stuff over.
Well, I've created the New User account, but I can't figure out how to move/copy my stuff into the user folders. After copying and attempting to move stuff in, I see folders with a red circle with a white line through it (like a 'no entry' sign).
Any clue as to how this can be done? All I'm trying to do is to reinstate the system prefs so they are not corrupt anymore on my log-in.No. Not the main Library folder. Make absolutely sure you are in the Home Library folder and not the main Library folder.
Your Home Library folder is hidden in Lion. To get to it, in the Finder menu, select GO and hold the option key down. Select Library in the submenu. The Finder window will open in your Home Library. This is where your user prefs are stored.
Once there, you will see the Preferences folder. Open it up, select all items within it and move them to the trash. You will need to restart in order for the new Finder preferences to be recreated.
Once you restart, then you will be back to the default preferences to the system and all applications. And yes, it will affect all settings including your Dock, just as logging into a new user. You will have to reset everything there also.
If you wish to do a selective method, instead of deleting all preferences, try deleting the one associated with your problem. Screen saver problems should be affected by the system preferences, so try deleting this:
com.apple.systempreferences.plist
com.apple.systempreferences.plist.lockfile
Note that when you delete system file preferences, a restart will be required. For applications, just quit the application before trashing preference files. -
How to load multiple CSV files into oracle in one go.
Hi,
I have project requirement like: I'll be getting one csv file as one record for the source table.
So i need to know is there any way by which I can load multiple csv in one go. I have searched a lot on net about external table.(but problem is I can only use one consolidate csv at a time)
and UTL_FILE same thing consolidate file is required here to load.
but in my scenario I'll have (1000+) csv files(as records) for the table and it'd be hectic thing to open each csv file,copy the record in it and paste in other file to make consolidate one.
Please help me ..it's very new thing for me...I have used external table for , one csv file in past but here I have to user many file.
Table description given below.
desc td_region_position
POSITION_KEY NUMBER Primary key
POSITION_NAME VARCHAR2(20)
CHANNEL VARCHAR2(20)
LEVEL VARCHAR2(20)
IS_PARTNER CHAR(1)
MARKET_CODE VARCHAR2(20)
CSV file example:
POSITION_KEY|POSITION_NAME|CHANNEL|LEVEL|IS_PARTNER|MARKET_CODE
123002$$FLSM$$Sales$$Middle$$Y$$MDM2203
delimeter is -- $$my database version as follows:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
"CORE 10.2.0.5.0 Production"
TNS for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - Productio
NLSRTL Version 10.2.0.5.0 - ProductionEdited by: 974253 on Dec 10, 2012 9:58 AMif your csv files have some mask, say "mask*.csv" or by file "mask1.csv" and "mask2.csv" and ...
you can create this.bat file
FOR %%c in (C:\tmp\loader\mask*.csv) DO (
c:\oracle\db\dbhome_1\BIN\sqlldr <user>@<sid>l/<password> control=C:\tmp\loader\loader.ctl data=%%c
)and C:\tmp\loader\loader.ctl is
OPTIONS (ERRORS=0,SKIP=1)
LOAD DATA
APPEND
INTO TABLE scott.td_region_position
FIELDS TERMINATED BY '$$' TRAILING NULLCOLS
( POSITION_KEY,
POSITION_NAME ,
CHANNEL,
LVL,
IS_PARTNER,
MARKET_CODE
)test
C:\Documents and Settings\and>sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Mon Dec 10 11:03:47 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Enter user-name: scott
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from td_region_position;
no rows selected
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options
C:\Documents and Settings\and>cd C:\tmp\loader
C:\tmp\loader>dir
Volume in drive C has no label.
Volume Serial Number is F87F-9154
Directory of C:\tmp\loader
12/10/2012 10:51 AM <DIR> .
12/10/2012 10:51 AM <DIR> ..
12/10/2012 10:55 AM 226 loader.ctl
12/10/2012 10:38 AM 104 mask1.csv
12/10/2012 10:39 AM 108 mask2.csv
12/10/2012 10:57 AM 151 this.bat
4 File(s) 589 bytes
2 Dir(s) 4,523,450,368 bytes free
C:\tmp\loader>this.bat
C:\tmp\loader>FOR %c in (C:\tmp\loader\mask*.csv) DO (c:\oracle\db\dbhome_1\BIN\
sqlldr user@orcl/password control=C:\tmp\loader\loader.ctl data=%c )
C:\tmp\loader>(c:\oracle\db\dbhome_1\BIN\sqlldr user@orcl/password control=C
:\tmp\loader\loader.ctl data=C:\tmp\loader\mask1.csv )
SQL*Loader: Release 11.2.0.1.0 - Production on Mon Dec 10 11:04:27 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
C:\tmp\loader>(c:\oracle\db\dbhome_1\BIN\sqlldr user@orcl/password control=C
:\tmp\loader\loader.ctl data=C:\tmp\loader\mask2.csv )
SQL*Loader: Release 11.2.0.1.0 - Production on Mon Dec 10 11:04:28 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
C:\tmp\loader>sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Mon Dec 10 11:04:46 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Enter user-name: scott
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from td_region_position;
POSITION_KEY POSITION_NAME CHANNEL LVL I
MARKET_CODE
123002 FLSM Sales Middle Y
MDM2203
123003 FLSM1 Sa2les M2iddle Y
MDM22203
SQL> -
How to read a .csv file(excel format) using Java.
Hi Everybody,
I need to read a .csv file(excel) and store all the columns and rows in 2d arrays. Then I can do the rest of the coding myself. I would like it if somebody could post their code to read .csv files over here. The .csv file can have different number of columns and different number of rows every time it is ran. The .csv file is in excel format, so I don't know if that affects the code or not. I would also appreciate it if the classes imported are posted too. I would also like to know if there is a way I can recognize how many rows and columns the .csv file has. I need this urgently so I would be very grateful to anybody who has the solution. Thanks.
Sincerely Taufiq.I used this
BufferedReader in = new BufferedReader (new FileReader ("test.csv"));
// and
StringTokenizer parser = new StringTokenizer (str, ", ");
while (parser.hasMoreTokens () == true)
{ //crap }works like a charm! -
Hi all,
I'm new to flex and have been asked to provide a small widget
that will display the contents of a csv in a list. Can I use the
HTTPService to open a csv file and then create an actionscript 3
function to parse it? If so can anyone point me to a tutorial on
how to parse a csv file please.
Thanks in advanceHello Sir,
I am new to flex and want to read a csv file and using below code but does not seems to be working. Can you please help?
i use below code but did not work
var file:File = evt.currentTarget as File;
file = file.resolvePath(file.nativePath);
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var fileData:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
var endings:Array = [File.lineEnding, "\n", "\r"];
but for some reason it return "ÐÏ ࡱá" funny value. Any idea why don't i get the correct data from file.
belwo is the csv file i am trying to open.
Title
Given_Name
Surname
Gong
Salutation
Position
Organisation
Address_Line_1
Address_Line_2
Address_Line_3
Suburb
State
Postcode
Country
Home_Phone
Fax
Other_Phone
User_Field_1
User_Field_2
User_Field_3
User_Field_4
Mobile_Phone
Second_Address
Second_Address_Line_1
Second_Address_Line_2
Second_Address_Line_3
Second_Suburb
Second_State
Second_Country
Second_Postcode
Langcode
Website
Mr.
Jeff
Alexander
Retention Marketing
Monday, April 13th, 2009
Mr.
Anthony
Demaso
Retention Marketing
Monday, April 13th, 2009
Sally
Swinamer
Yield
Monday, April 13th, 2009
Chris
Torbay
Yield
Monday, April 13th, 2009
Annette
Warring
Genesis Vizeum
Monday, April 13th, 2009
Mr.
Mark
Khoury
Genesis Vizeum
Monday, April 13th, 2009
Mr.
Andy
Thorndyke
Thorsons
Monday, April 13th, 2009
Shannon
Rutherford
Central Reproductions
Monday, April 13th, 2009
Mr.
Rob
Greenwood
Central Reproductions
Monday, April 13th, 2009
Lisa
Marchese
Des Rosiers
Monday, April 13th, 2009
Mr.
Michael
Whitcombe
McMillan LLP
Monday, April 13th, 2009
Thanks,
Gill -
How to read a .CSV file using UTL_FILE
HI,
How do i read a .csv file line by line using UTL_FILE?
Thanks in advance
Regards,
Gayatri----do open the file logic
begin
----Let's say this file is delimited by ','
---declare variables
v_startPos number; -- starting position of field
v_Pos number; -- position of string
v_lenString number; -- length
v_first_field varchar2(30);
v_second_field varchar2(30);
v_third_field varchar2(30);
v_fourth_field varchar2(30);
input_String varchar2(1000); -- buffer for each line of file
----Say you have a 4 column file delimited by ','
delimitChar varchar2(1) := ','
Joe;Joan;People;Animal
Teddy;Bear;Beans;Toys
begin
loop
utl_file.get_line(input_file, input_String); -- get each line
---- this will get the first field as specified by the last number
v_Pos := instr(input_String,delChar,1,1);
v_lenString := v_Pos - 1;
v_first_field := substr(input_String,1,v_lenString);
v_startPos := v_Pos + 1;
-- this will get the second field
v_Pos := instr(inString,delChar,1,2);
v_lenString := v_Pos - v_startPos;
v_second_field := substr(input_String,v_startPos,v_lenString);
v_startPos := v_Pos + 1;
-- 3rd field
v_Pos := instr(inString,delChar,1,3);
v_lenString := v_Pos - v_startPos;
v_third_field := substr(input_String,v_startPos,v_lenString);
v_startPos := v_Pos + 1;
-- last field -- there is no delimiter for last field
v_Pos := length(input_String) + 1;
v_lenString := v_Pos - v_startPos;
v_fourth_field := substr(input_String,v_StartPos,v_lenString);
end;
EXCEPTION
WHEN no_data_found then
fnd_file.put_line(FND_FILE.LOG, 'Last line so exit');
exit;
end loop;
Maybe you are looking for
-
Can't update or restore my ipod - please help
It only seems that i can synch my ipod when i plug it in when windows loads up. Itunes automatically loads up and my ipod synchs. But then if later i want to synch again as i have added new stuff it won't. When i try to restore it to the factory sett
-
How do I configure an account just for SMTP in Mail?
I can't see how you can set up accounts manually in Mail any longer. I want to set up an account allowing me to use a particular smtp server to send messages from my University email address. The University concerned uses Exchange (grrr) and all the
-
Which mapping populates W_INVOICE_FS in Oracle EBS Adaptor?
Which mapping populates W_INVOICE_FS in Oracle EBS Adaptor? I was not able to find any mapping that populates W_INVOICE_FS staging table. Thanks Eric
-
I have restored my ipod and now the songs in my library wont sync onto it:)).. !! please help!!
-
File to File ------ Message getting stuck in Integration Engine
Hi All, I have a small issue in file to file scenario . Once I send the file .Its getting picked up from the source directory but its not getting delivered to the destination directory. When I check in SXMB_MONI ,message is successfully processed. No