How to store data into a file from a host VI developed for Compact RIO
Hi,
I am new to the CompactRIo.I have developed a VI which runs on the FPGA(CompactRIO) which continuously monitors tha data from a system and i have developed a host VI to read the data and i am successfully getting the data into my computer and i want that data to store into a file.When i use the write to spreadsheet VI for writing into a file.The data is not written into file can anybody tell me why this is happening?
Hi,
The last one you said is working when i conected through it is working, whatever files i have used earlier are there.Thanks for that but i have few queries please answer me so that i acn proceed in my project.
1.As you said to connect to ftp://xx.xx.xx.xx i have seen some extra files along with my files waht are they? waether my data files are stored in flash memory of RT controller?if so, how to clear those files?
2.Suppose i want to clean up the flash memory of RT contrller i.e suppose i have deployed some file earlier , now i want to cleanup those i dumped into the memory how to do that?
3.How to disable the Application running on the RT controller when it powers on? i.e. when i switch on the power it should be connected but nothing hould be running on.
4.I mean at the end of the experiment when i stopped the host VI by pressing stop button weather application running on the RT controller will stop and weather FPGA VI runnibg on that also stop if not how to stop?
5.Suppose next time when i connect to ftp://xx.xx.xx.xx i dont want to keep earlier files there how to delete them?Because my doubt is if i am using the file name which is same as the prevoius one there is aproblem of appending the new data to the old file.?
Regards,
Vishnu
Similar Messages
-
How to store data into log file(.doc) using CVI
The purpose is to store the capture data(from my cvi program) and store into the log file (.doc). so at the end of the program run I can retrieve the doc file where the data store to do my analysing .
Why do this: I wanted to create my program into .exe file that why I need this method or do u have other method to intro?
Any ideal or note or example to share? Pls helpIf you are explicitly trying to create a Microsoft Word document, then CVI comes with Word Report instrument that can be used to generate such files. The instrument is located in toolslib\activex\word\wordreport.fp, while a sample program can be found in samples\activex\word\wordrpt.cws.
I suggest you take a look at the example program that illustrates the fundamentals of this instrument, next you can start designing your own application using that instrument.
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
How to extract data into excel file from more than one internal table
Hi Guys
I want to extract the data from module pool screen.
In screen there are two internal tables
1. header
2. items.
I want to extract the data as same format looking in the screen.
With simple Download FM we cannot do this one, because in this we will display as continuous rows.
<b> But my requirement is saving as table with heading, date, header details</b>
Note that it is not the simple down load . Suggest me with example codingHi Guys,
I think it depends on which software you will use to see the result.
If U are using Excel, it's very easy to achieve it.
1. Define a structure as string, the lenth depend on your need.And use the structure to define a internal table, supposed is as A..
2. Concatenate the head data using some separator, for ex. a comma; and then add this into A.
3. The above step's concatenate is depend on your format for request;For ex, you want to place the date at the 4th cell in excel, that means you should put three separator before the date field.
4 Concatenate the item data into the download table.
5. Download the table to file.
6. Display the file, using your defined separator.
Hope this helpful.
Bob -
How to store data (in tdm files)
I'm looking for advice on how to store data in tdm/tdx files.
The main challenge is like this: At regular time intervals there is new data available (say every 10 minutes there are 10 minutes of new data available). All data is time based. So every ten minutes I may create a new tdm/tdx file containing this data segment. However, when i want to analyze the data i dont necessarily want to view 10 minutes of data from all channels, but maybe 20 hours of data from one particular channel.
The way I've achieved this so far is to manually load each 10 minute segment of this particular channel and then add these parts together. This is both time consuming and cumbersome. Is there a better way to do this that I've simply not discovered yet? Is there a better way to store data to simplify this process?
One solution is of course to save data from several 10-minute frames in one file, but seeing as there is a never ending supply of data i cant simply save all data in one giant file, it has to be split up at some point, and the problem will still remain.
One factor to have in mind here is that this is rather large amounts of data (maybe 10GB each day), so the option to simply load all the data into memory goes out the window rather quickly.
Feel free to ask if I've not made myself very clearHi salte,
If your test ever ended, and if you had LabVIEW 8.20 or higher, I would recommend using a TDMS file, which handles data appeands flawlessly. DIAdem 10.1 now also does data reduction and index windowing during file loading for TDM / TDMS / DataPlugin files, so that you could easily load out only the part of the file you wanted to look at. But since you describe your data acquisition as never stopping and amassing 10 GB per day, I agree that it would be impractical to use only 1 data file. So we are stuck with some number of files which each contain a part of your measurement. This approach can have advantages, since you can save operational properties for each "buffer" such as average value, dominant frequency, ambient room temperature, etc., and later on you can use the DataFinder to query out only the data buffers which meet specific conditions based on these properties. The problem remains to load and assemble data based on multiple files. This is an old problem in DIAdem, and one for which I have an efficient and I hope satisfactory workaround application. It does what you describe already doing in the minimum amount of time and with the minimum amount of user interaction, and it can be highly parametrized to suit your particular situation. The ideal way to start the application would be as part of a ResultsList custom menu. This would enable you to query out the buffers you wanted, highlight those rows in the ResultsList, right-click and choose your custom menu, and WHAM! the selected buffers for your queried channel(s) are automatically appended together in the DataPortal. Launching from a ResultsList custom menu would mean that you could skip the file dialog and just read out the data sources directly from the ResultsList selection.
Let me know what you think,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
Attachments:
Importing Data from Multiple DataPlugin Files.zip 198 KB -
How to insert data into a table from an xml document
using the XmlSql Utility, how do I insert data into a table from an xml document, using the sqlplus prompt.
if i use the xmlgen.insertXML(....)
requires a CLOB file, which i dont have, only the xml doc.
Cant i insert directly from the doc to the table?
the xmlgen examples I have seen first convert a table to a CLOB xmlString and then insert it into another table.
Isnt there any other way?Your question is little perplexing.
If you're using XML SQL Utility from
the commandline, just use putXML.
java OracleXML putXML
null -
Hi ABAP Exterts,
Any one help on this , there is a requirement to download the data into XLSX file only.
I am able to to download the data into XLS file using the FM: GUI_DOWNLOAD in SAP ECC 6.0and also opening the file . But when i download the data into XLSX file . I am able to download the data into GUI_DOWNLOAD. But while opening the file i am getting the below mentioned error.
'Excel cannot open the file 'filename.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file'
Ok buttom is coming not able to open the file.
When i use the FM: SAP_CONVERT_TO_XLS_FORMAT to download the XLS it self it is going abap DUMP that file type error.
Any one help any Function Module or how to download data through abap programing into XLSX file.
Thanks.
Murali.
Message was edited by: Matthew Billingham - adjusted wording...If you want to download your ALV to an .XLXS format file, with all the formatting intact, please try the following code. I have tried to create a custom Function module Z_EXCEL_DOWNLOAD_TEST wherein I pass all the callback variables, the final ALV internal table and all the ALV details like field catalog, sort, layout, event list and so on, along with the concatenated file path and file name in I_FILE. I have used a custom class ZCL_SALVEXPORT_XML which is a copy of the standard class CL_SALV_EXPORT_XML_DIALOG, with few modifications in Method: EXECUTE and Method: DOWNLOAD. The methods where I have modified the code are also shown at the end.
****************Global declarations***********************
TYPE-POOLS: slis,
kkblo.
TYPES: t_fccls(1) TYPE c OCCURS 0.
TYPES: BEGIN OF ty_nosum,
fieldname TYPE kkblo_fieldname, "Field name
tabname TYPE kkblo_tabname, "Table name
fieldname_dep TYPE kkblo_fieldname, "Field name
tabname_dep TYPE kkblo_tabname, "Table name
index TYPE sy-index, "Index
END OF ty_nosum.
TYPES: t_nosum TYPE TABLE OF ty_nosum INITIAL SIZE 0 WITH NON-UNIQUE DEFAULT KEY.
TYPES: BEGIN OF ty_dep_field,
s_dep_fieldcat TYPE kkblo_fieldcat, "Field cat
t_ref_fieldcat TYPE kkblo_t_fieldcat, "Field cat
END OF ty_dep_field.
TYPES: BEGIN OF ty_ref_field,
s_ref_fieldcat TYPE kkblo_fieldcat, "Field cat
s_dep_fieldcat TYPE kkblo_fieldcat, "Field cat
END OF ty_ref_field.
TYPES: t_dep_field TYPE ty_dep_field OCCURS 0. "
TYPES: t_ref_field TYPE ty_ref_field OCCURS 0.
TYPES: BEGIN OF ty_memory,
object(20) TYPE c, "Object
memcount(4) TYPE c, "count
END OF ty_memory.
*ALV Customer Wrapper
TYPES: BEGIN OF ty_type_header_info,
tabname TYPE kkblo_tabname, "Table name
fieldname TYPE kkblo_fieldname, "Field name
sequence TYPE i, "Sequence
field TYPE char80, "Field
pagno TYPE sypagno, "Page num
linno TYPE sy-linno, "Current Line in List
colno TYPE sy-colno, "Current List Column
END OF ty_type_header_info,
t_type_header_info TYPE SORTED TABLE OF ty_type_header_info
WITH UNIQUE KEY tabname fieldname.
TYPES: BEGIN OF ty_type_row_info,
tabname TYPE kkblo_tabname, "Table name
tabindex TYPE syindex, "Index
field TYPE char80, "Field name
pagno TYPE sypagno, "Page num
linno TYPE sy-linno, "Current Line in List
colno TYPE sy-colno, "Current List Column
END OF ty_type_row_info,
t_type_row_info TYPE SORTED TABLE OF ty_type_row_info
WITH UNIQUE KEY tabname tabindex.
TYPES: BEGIN OF ty_type_sel_header,
tabname TYPE kkblo_tabname, "table name
fieldname TYPE kkblo_fieldname, "field name
END OF ty_type_sel_header,
t_type_sel_header TYPE SORTED TABLE OF ty_type_sel_header
WITH UNIQUE KEY tabname fieldname.
TYPES: BEGIN OF ty_type_sel_row,
tabname TYPE kkblo_tabname,
tabindex TYPE syindex,
END OF ty_type_sel_row,
t_type_sel_row TYPE SORTED TABLE OF ty_type_sel_row
WITH UNIQUE KEY tabname tabindex.
TYPES: BEGIN OF ty_type_sel_cell,
tabname TYPE kkblo_tabname,
tabindex TYPE syindex,
fieldname TYPE kkblo_fieldname,
END OF ty_type_sel_cell.
TYPES: BEGIN OF ty_type_selections,
t_row_info TYPE t_type_row_info,
t_header_info TYPE t_type_header_info,
t_selected_headers TYPE t_type_sel_header,
t_selected_rows TYPE t_type_sel_row,
s_current_cell TYPE ty_type_sel_cell,
set_headers TYPE sap_bool,
set_rows TYPE sap_bool,
set_current_cell TYPE sap_bool,
END OF ty_type_selections.
TYPES: BEGIN OF ty_stack3,
r_grid TYPE REF TO cl_gui_alv_grid, "Y6DK050176
r_salv_adapter TYPE REF TO if_salv_adapter,
s_selections TYPE ty_type_selections,
r_print_state TYPE REF TO if_alv_print_parameter_proxy, "Y6DK075821
suppress_empty_data TYPE abap_bool,
END OF ty_stack3.
TYPES: t_stack3 TYPE ty_stack3 OCCURS 0.
TYPES: BEGIN OF ty_stack,
i_callback_program TYPE sy-repid,
i_callback_user_command TYPE kkblo_formname,
i_callback_top_of_page TYPE kkblo_formname,
i_callback_top_of_list TYPE kkblo_formname,
i_callback_end_of_page TYPE kkblo_formname,
i_callback_end_of_list TYPE kkblo_formname,
i_callback_pf_status_set TYPE kkblo_formname,
i_callback_fieldcat_save TYPE kkblo_formname,
i_callback_layout_save TYPE kkblo_formname,
i_tabname TYPE kkblo_tabname,
i_tabname_slave TYPE kkblo_tabname,
is_keyinfo TYPE kkblo_keyinfo,
is_layout TYPE kkblo_layout,
it_fieldcat TYPE kkblo_t_fieldcat,
i_fctype(1) TYPE c,
it_excluding TYPE kkblo_t_extab,
it_special_groups TYPE kkblo_t_sp_group,
it_sort TYPE kkblo_t_sortinfo,
it_except_qinfo TYPE kkblo_t_qinfo,
is_sel_hide TYPE kkblo_sel_hide,
t_columns TYPE kkblo_t_columns,
t_filter TYPE kkblo_t_filter,
s_lprint TYPE kkblo_lprint,
print_line_break TYPE char1,
t_isetab TYPE kkblo_seldis,
t_fccls TYPE t_fccls,
t_sfinfo TYPE kkblo_t_sfinfo,
t_ref_field TYPE t_ref_field,
t_dep_field TYPE t_dep_field,
flg_default_status(1) TYPE c,
flg_selections TYPE char1,
flg_allow_no_selection TYPE char1,
flg_input TYPE char1,
flg_called TYPE char1,
flg_popup TYPE char1,
flg_endlist TYPE char1,
listtype TYPE char1,
actcols TYPE i,
is_list TYPE char1,
END OF ty_stack.
TYPES: t_stack TYPE ty_stack OCCURS 0.
TYPES: BEGIN OF ty_stack2,
button_col1(20) TYPE c,
button_col2(20) TYPE c,
button_col3(20) TYPE c,
button_col4(20) TYPE c,
button_col5(20) TYPE c,
s_header TYPE kkblo_header,
t_sfinfo_slave TYPE kkblo_t_sfinfo,
t_suminfo TYPE kkblo_t_sfinfo,
t_sfsave TYPE kkblo_t_sfinfo,
t_nosum TYPE t_nosum,
window_title TYPE rsmpe-tittext, " Item_selection
flg_scroll_to_line(1) TYPE c, " Item_selection
flg_top_of_page(1) TYPE c,
flg_subtot(1) TYPE c,
flg_output_in_progress(1) TYPE c,
flg_grouplevels(1) TYPE c,
flg_groupedit(1) TYPE c,
flg_calculate_totals(1) TYPE c,
sumlevel TYPE sy-tabix,
memory_stack1 TYPE ty_memory,
memory_stack2 TYPE ty_memory,
memory_outtab TYPE ty_memory,
t_colmark TYPE kkblo_t_colmark,
t_rowmark TYPE kkblo_t_rowmark,
it_event_exit TYPE kkblo_t_event_exit,
t_groups TYPE kkblo_t_grouplevels,
t_filter_groups TYPE kkblo_t_grouplevels,
s_subtot_options TYPE kkblo_subtot_options,
flg_append_mode(1) TYPE c,
is_reprep_id TYPE kkblo_reprep_id,
i_callback_before_line_output TYPE kkblo_formname,
i_callback_after_line_output TYPE kkblo_formname,
i_callback_foreign_top_of_page TYPE kkblo_formname,
i_callback_foreign_end_of_page TYPE kkblo_formname,
i_callback_list_modify TYPE kkblo_formname,
i_callback_top_of_coverpage TYPE kkblo_formname,
i_callback_end_of_coverpage TYPE kkblo_formname,
i_callback_grouplevel_change TYPE kkblo_formname,
i_callback_item_data_expand TYPE kkblo_formname,
i_callback_header_transport TYPE kkblo_formname,
i_callback_reprep_sel_modify TYPE kkblo_formname,
i_callback_subtotal_text TYPE kkblo_formname,
END OF ty_stack2.
TYPES: t_stack2 TYPE TABLE OF ty_stack2 INITIAL SIZE 0.
** *--- iTables
DATA: it_stack TYPE t_stack WITH HEADER LINE.
DATA: it_stack2 TYPE t_stack2 WITH HEADER LINE.
***ALV Customer Wrapper
DATA: it_stack3 TYPE t_stack3 WITH HEADER LINE.
CONSTANTS: BEGIN OF c_con_listtype,
simple(1) TYPE c VALUE 'S',
hier_sequ(1) TYPE c VALUE 'H',
matrix(1) TYPE c VALUE 'M',
END OF c_con_listtype.
DATA: gv_callback_program1 TYPE sy-repid,
gv_callback_user_command1 TYPE kkblo_formname,
gv_callback_top_of_page1 TYPE kkblo_formname,
gv_callback_top_of_list1 TYPE kkblo_formname,
gv_callback_end_of_page1 TYPE kkblo_formname,
gv_callback_end_of_list1 TYPE kkblo_formname,
gv_callback_pf_status_set1 TYPE kkblo_formname,
gv_callback_layout_save1 TYPE kkblo_formname,
gv_callback_fieldcat_save1 TYPE kkblo_formname,
gv_callback_grouplevel_change1 TYPE kkblo_formname,
gv_callback_before_line_otput1 TYPE kkblo_formname,
gv_callback_after_line_otput1 TYPE kkblo_formname,
gv_callback_foreign_top_of_pg1 TYPE kkblo_formname,
gv_callback_foreign_end_of_pg1 TYPE kkblo_formname,
gv_callback_list_modify1 TYPE kkblo_formname,
gv_callback_top_of_coverpge1 TYPE kkblo_formname,
gv_callback_end_of_coverpge1 TYPE kkblo_formname,
gv_callback_item_data_expand1 TYPE kkblo_formname,
gv_callback_header_transport1 TYPE kkblo_formname,
gv_callback_reprep_sel_modify1 TYPE kkblo_formname,
gv_callback_subtotal_text1 TYPE kkblo_formname,
gv_layout1 TYPE kkblo_layout,
gv_fieldcat1 TYPE kkblo_t_fieldcat,
gv_fctype1 TYPE c,
gv_event_exit1 TYPE kkblo_t_event_exit,
gv_excluding1 TYPE kkblo_t_extab,
gv_special_groups1 TYPE kkblo_t_sp_group,
gv_sort1 TYPE kkblo_t_sortinfo,
gv_filter1 TYPE kkblo_t_filter,
gv_except_qinfo1 TYPE slis_t_qinfo_alv,
gv_sel_hide1 TYPE slis_sel_hide_alv,
gv_reprep_id1 TYPE slis_reprep_id,
gv_screen_start_column1 TYPE i,
gv_salv_adapter1 TYPE REF TO if_salv_adapter,
gv_suppress_empty_data1 TYPE sap_bool.
FUNCTION z_excel_download_test.
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_BYPASSING_BUFFER) TYPE CHAR01 OPTIONAL
*" REFERENCE(I_BUFFER_ACTIVE) OPTIONAL
*" REFERENCE(I_CALLBACK_PROGRAM) TYPE SY-REPID OPTIONAL
*" REFERENCE(I_CALLBACK_USER_COMMAND) OPTIONAL
*" REFERENCE(I_CALLBACK_TOP_OF_PAGE) OPTIONAL
*" REFERENCE(I_CALLBACK_TOP_OF_LIST) OPTIONAL
*" REFERENCE(I_CALLBACK_END_OF_PAGE) OPTIONAL
*" REFERENCE(I_CALLBACK_END_OF_LIST) OPTIONAL
*" REFERENCE(I_CALLBACK_PF_STATUS_SET) OPTIONAL
*" REFERENCE(I_CALLBACK_LAYOUT_SAVE) OPTIONAL
*" REFERENCE(I_CALLBACK_FIELDCAT_SAVE) OPTIONAL
*" REFERENCE(I_CALLBACK_GROUPLEVEL_CHANGE) OPTIONAL
*" REFERENCE(I_CALLBACK_BEFORE_LINE_OUTPUT) OPTIONAL
*" REFERENCE(I_CALLBACK_AFTER_LINE_OUTPUT) OPTIONAL
*" REFERENCE(I_CALLBACK_FOREIGN_TOP_OF_PAGE) OPTIONAL
*" REFERENCE(I_CALLBACK_FOREIGN_END_OF_PAGE) OPTIONAL
*" REFERENCE(I_CALLBACK_LIST_MODIFY) OPTIONAL
*" REFERENCE(I_CALLBACK_TOP_OF_COVERPAGE) OPTIONAL
*" REFERENCE(I_CALLBACK_ITEM_DATA_EXPAND) OPTIONAL
*" REFERENCE(I_CALLBACK_END_OF_COVERPAGE) OPTIONAL
*" REFERENCE(I_CALLBACK_HEADER_TRANSPORT) OPTIONAL
*" REFERENCE(I_CALLBACK_REPREP_SEL_MODIFY) OPTIONAL
*" REFERENCE(I_CALLBACK_SUBTOTAL_TEXT) OPTIONAL
*" REFERENCE(I_TABNAME) TYPE SLIS_TABNAME OPTIONAL
*" REFERENCE(I_FCTYPE) DEFAULT 'R'
*" REFERENCE(IT_EXCEPT_QINFO) TYPE SLIS_T_QINFO_ALV OPTIONAL
*" REFERENCE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL
*" REFERENCE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL
*" REFERENCE(I_SCREEN_START_COLUMN) DEFAULT 0
*" REFERENCE(I_OO_ALV) OPTIONAL
*" REFERENCE(IR_SALV_ADAPTER) TYPE REF TO IF_SALV_ADAPTER OPTIONAL
*" REFERENCE(I_SUPPRESS_EMPTY_DATA) TYPE SAP_BOOL DEFAULT
*" ABAP_FALSE
*" REFERENCE(I_FILE) TYPE STRING OPTIONAL
*" REFERENCE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL
*" REFERENCE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL
*" REFERENCE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL
*" REFERENCE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL
*" REFERENCE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL
*" REFERENCE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL
*" REFERENCE(IS_KEYINFO) TYPE SLIS_KEYINFO_ALV OPTIONAL
*" REFERENCE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL
*" REFERENCE(IS_LIST_SCROLL) TYPE SLIS_LIST_SCROLL OPTIONAL
*" REFERENCE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL
*" REFERENCE(IS_LINEINFO) TYPE SLIS_LINEINFO OPTIONAL
*" REFERENCE(I_REPID) TYPE SYREPID OPTIONAL
*" TABLES
*" T_OUTTAB TYPE STANDARD TABLE OPTIONAL
*********** Local data declarations******************
DATA: gv_list TYPE char1.
DATA: gv_fcat_complete TYPE sap_bool.
DATA: gv_buffer_active TYPE char01,
wa_variant TYPE disvariant.
DATA: gv_controller TYPE REF TO cl_salv_export_c8r.
DATA: gv_xml TYPE xstring.
DATA: gv_s_xml_choice TYPE if_salv_bs_xml=>s_type_xml_choice.
DATA: gv_t_xml_choice TYPE if_salv_bs_xml=>t_type_xml_choice.
DATA: gv_param_lvc TYPE if_salv_export=>s_type_param_lvc.
DATA: gv_data TYPE REF TO data.
DATA: gv_result_data TYPE REF TO cl_salv_ex_result_data_table.
DATA: gv_flavour TYPE string.
DATA: gv_version TYPE string.
DATA: -
How to load data into an ods from multiple info sources.
hi all...
i am given a task to load data into an ods from 3 infosources ...
can someone plz give me the flow .
thank u in advance..Hi Hara Pradhan,
You have to create 3 update rules by giving the 3 different infosources while creating each update rule. And u have to create the infopackages under each infosource. with this u can load the data to the same data target from multiple info sources.
Hope it helps!
Assign points if it helps! -
HOW TO INSERT DATA INTO SQL SERVER FROM MS ACCESS TABLE??
NEED TO INSERT DATA INTO SQL SERVER FROM MS ACCESS TABLE.
this is another method
http://www.mssqltips.com/sqlservertip/2484/import-data-from-microsoft-access-to-sql-server/
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to store data into database by reading sql statements from text file
how to write java program for storing data into database by reading sql statements from text file
Step 1: Create a property file to add various queries.
Step 2: Read the properties file using ResourceBundle
Step 3: Use the jdbc to execute the query read from the property file.
So in future if you need to change query no need do any modifications in java program. But depends on how you use the property file. -
How to input data into an arraylist from a text file?
I am trying to take data from a text file and put that data into an arraylist. First here is the text file:
[item1, 10, 125.0, item2, 10, 12.0, item3, 20, 158.0]
3
4530.0
[item5, 65, 555.5, item4, 29, 689.0]
2
56088.5
[item7, 84, 34.5, item6, 103, 0.5, item8, 85, 1.36]
3
3065.1The text between the [ ] is the output from my arraylists. I have three arraylists. The first [ ] belongs to arraylist A, the second to arraylist B, and the third to arraylist C. The format of the arraylists is this:
<item name>,<# in stock>,<value of one item>
The first number below the arraylists in the text file represents the number of items in the list. The second number below the arraylists represents the total value of the items in the arraylists.
Here is the class file I have (yes, it does everything):
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public class Inventory extends Object
public int toAdd = 0;
private boolean done = false; //Are we done yet?
public String strItemName; //The name of the item type.
public int intNumInStock; //The number in stock of that type.
public double dblValueOfOneItem; //The value of one item.
public String strNumberInStock;
public double dblTotalValueA; //The total value of warehouse A.
public double dblTotalValueB; //The total value of warehouse B.
public double dblTotalValueC; //The total value of warehouse C.
public int intWarehouseAItemCount; //Counter for items in warehouse A.
public int intWarehouseBItemCount; //Counter for items in warehouse B.
public int intWarehouseCItemCount; //Counter for items in warehouse C.
ArrayList warehouseAList = new ArrayList(); //Create the Warehouse A ArrayList.
ArrayList warehouseBList = new ArrayList(); //Create the Warehouse B arrayList.
ArrayList warehouseCList = new ArrayList(); //Create the Warehouse C arrayList.
/** Construct a new Inventory object. */
public Inventory()
super();
/**Add items to the Warehouse A ArrayList.*/
private void createWareHouseA()
System.out.println("!" + toAdd + " item types will be added to warehouse A.");
//Cast
String strNumInStock = Integer.toString(intNumInStock);
String strValueOfOneItem = Double.toString(dblValueOfOneItem);
this.strNumberInStock = strNumInStock;
System.out.println("!Initial size of warehouseAList : " +
warehouseAList.size());
//Add items to the array List
warehouseAList.add(this.strItemName);
warehouseAList.add(this.strNumberInStock);
warehouseAList.add(this.dblValueOfOneItem);
System.out.println("!size of arrayList after additions " + warehouseAList.size());
/**Add items to the Warehouse B ArrayList.*/
private void createWareHouseB()
System.out.println("!" + toAdd + " item types will be added to warehouse B.");
//Cast
String strNumInStock = Integer.toString(intNumInStock);
String strValueOfOneItem = Double.toString(dblValueOfOneItem);
this.strNumberInStock = strNumInStock;
System.out.println("!Initial size of warehouseBList : " +
warehouseBList.size());
//Add items to the array List
warehouseBList.add(this.strItemName);
warehouseBList.add(this.strNumberInStock);
warehouseBList.add(this.dblValueOfOneItem);
System.out.println("!size of arrayList after additions " + warehouseBList.size());
/**Add items to the Warehouse C ArrayList.*/
private void createWareHouseC()
System.out.println("!" + toAdd + " item types will be added to warehouse C.");
//Cast
String strNumInStock = Integer.toString(intNumInStock);
String strValueOfOneItem = Double.toString(dblValueOfOneItem);
this.strNumberInStock = strNumInStock;
System.out.println("!Initial size of warehouseCList : " +
warehouseCList.size());
//Add items to the array List
warehouseCList.add(this.strItemName);
warehouseCList.add(this.strNumberInStock);
warehouseCList.add(this.dblValueOfOneItem);
System.out.println("!size of arrayList after additions " + warehouseCList.size());
/**Interpret the commands entered by the user.*/
public void cmdInterpreter()
this.displayHelp();
Scanner cin = new Scanner(System.in);
while (!this.done)
System.out.print(">");
//"line" equals the next line of input.
String line = cin.nextLine();
this.executeCmd(line);
/**Execute one line entered by the user.
* @param cmdLN; The command entered by the user to execute. */
private void executeCmd(String cmdLN)
Scanner line = new Scanner(cmdLN);
if (line.hasNext())
String cmd = line.next();
//What to do when users enter the various commands below.
if (cmd.equals("help"))
this.displayHelp();
else if (cmd.equals("Q!"))
this.done = true;
else if (cmd.equals("F") && line.hasNext())
this.inputFromFile(line.next());
else if (cmd.equals("K") && line.hasNext())
int numItemsToAdd = Integer.valueOf( line.next() ).intValue();
this.toAdd = numItemsToAdd;
this.inputFromKeyboard(numItemsToAdd);
/**What to do if input comes from a file.
* @param inputFile; The name of the input file to process.*/
private void inputFromFile(String inputFile)
Scanner cin = new Scanner(System.in);
System.out.println("!Using input file " + inputFile + ".");
System.out.print("!Enter the name of the output file: ");
String outputFile = cin.next();
System.out.println("!Using output file " + outputFile + ".");
try
BufferedReader in = new BufferedReader(new FileReader(inputFile));
//Scanner in = new Scanner(new File(inputFile));
//Initialize the String variables.
String line1 = null;
String line2 = null;
String line3 = null;
String line4 = null;
String line5 = null;
String line6 = null;
String line7 = null;
String line8 = null;
String line9 = null;
System.out.println(in.equals(",") + " see?");
//System.out.println((char)(char)in.read() + " experiment");
/**This loop assigns values to the string variables based on the
* values on each line in the input file. */
while(in.readLine() != null)
line1 = in.readLine();
line2 = in.readLine();
line3 = in.readLine();
line4 = in.readLine();
line5 = in.readLine();
line6 = in.readLine();
line7 = in.readLine();
line8 = in.readLine();
line9 = in.readLine();
//Print the contents of each line in the input file.
System.out.println("!value of line 1: " + line1);
System.out.println("!value of line 2: " + line2);
System.out.println("!value of line 3: " + line3);
System.out.println("!value of line 4: " + line4);
System.out.println("!value of line 5: " + line5);
System.out.println("!value of line 6: " + line6);
System.out.println("!value of line 7: " + line7);
System.out.println("!value of line 8: " + line8);
System.out.println("!value of line 9: " + line9);
/**Add items to the warehouses.*/
warehouseAList.add(line1);
warehouseBList.add(line4);
warehouseCList.add(line7);
/**Add the item count and total value for warehouse A.*/
int intLine2 = Integer.valueOf(line2).intValue();
this.intWarehouseAItemCount = intLine2;
double dblLine3 = Double.valueOf(line3).doubleValue();
this.dblTotalValueA = dblLine3;
/**Add the item count and total value for warehouse B.*/
int intLine5 = Integer.valueOf(line5).intValue();
this.intWarehouseBItemCount = intLine5;
double dblLine6 = Double.valueOf(line6).doubleValue();
this.dblTotalValueB = dblLine6;
/**Add the item count and total value for warehouse C.*/
int intLine8 = Integer.valueOf(line8).intValue();
this.intWarehouseCItemCount = intLine8;
double dblLine9 = Double.valueOf(line9).doubleValue();
this.dblTotalValueC = dblLine9;
/**Ask the user how many items to add or delete from inventory.*/
System.out.print("Enter the number to add to inventory for " +
warehouseAList.get(0) + ":");
String toAddOrDel = cin.next();
/**Print the contents of all the warehouses. */
System.out.println(" ");
//Print the contents of warehouse A.
System.out.println("!--------------------------------");
System.out.println("!----------Warehouse A:----------");
System.out.println("!--------------------------------");
//Print the item list for warehouse A.
System.out.println(warehouseAList);
//Print the total amount of items in warehouse A.
System.out.println("Total items: " + this.intWarehouseAItemCount);
//Print the total value of the items in warehouse A.
System.out.println("Total value: " + this.dblTotalValueA);
System.out.println("!--------------------------------");
System.out.println("!----------Warehouse B:----------");
System.out.println("!--------------------------------");
//Print the item list for warehouse B.
System.out.println("!warehouseB: " + warehouseBList);
//Print the total amount of items in warehouse B.
System.out.println("Total items: " + this.intWarehouseBItemCount);
//Print the total value of the items in warehouse B.
System.out.println("Total value: " + this.dblTotalValueB);
System.out.println("!--------------------------------");
System.out.println("!----------Warehouse C:----------");
System.out.println("!--------------------------------");
//Print the item list for warehouse C.
System.out.println("!warehouseC: " + warehouseCList);
//Print the total amount of items in warehouse C.
System.out.println("Total items: " + this.intWarehouseCItemCount);
//Print the total value of the items in warehouse C.
System.out.println("Total value: " + this.dblTotalValueC);
in.close();
catch (FileNotFoundException e)
System.out.println("!Error: Unable to open file for reading.");
catch (EOFException e)
System.out.println("!Error: EOF encountered, file may be corrupted.");
catch (IOException e)
System.out.println("!Error: Cannot read from file.");
/**What to do if input comes from the keyboard.
* @param numItems; The total number of items that will be added to the
* Warehouse(s). */
public void inputFromKeyboard(int numItems)
System.out.println("!You will be adding " + numItems + " items to " +
"inventory from the keyboard. ");
this.toAdd = numItems;
Scanner cin = new Scanner(System.in);
//Prompt user for name of output file.
System.out.print("!Enter the name of the output file: ");
String outputFile = cin.next();
/**This loop asks the user for information about the item(s) and inputs
*them into the appropriate array.*/
int count = 0;
while (numItems > count)
//Item name.
System.out.print("!Item name: ");
String addItemName = cin.next();
//Number in stock.
System.out.print("!Number in stock: ");
String addNumInStock = cin.next();
//Initial warehouse.
System.out.print("!Initial warehouse(A,B,C): ");
String addInitWarehouse = cin.next();
//Value of one item.
System.out.print("!Value of one item: ");
String addValueOfOneItem = cin.next();
//Add or delete from inventory
System.out.print("!Enter amount to add or delete from inventory: ");
String strAddOrDelete = cin.next();
System.out.println("!Amount to add or delete: " + strAddOrDelete);
//Cast
int intAddNumInStock = Integer.valueOf(addNumInStock).intValue();
double doubleAddValueOfOneItem = Double.valueOf(addValueOfOneItem).doubleValue();
int intAddOrDelete = Integer.valueOf(strAddOrDelete).intValue();
/**Add intAddNumInStock with intAddOrDelete to determine the amount
* to add or delete from inventory (If a user wishes to remove items
* from inventory simply add negative values). */
intAddNumInStock = intAddNumInStock + intAddOrDelete;
System.out.println("!Inventory after modifications: " + strAddOrDelete);
this.strItemName = addItemName;
this.intNumInStock = intAddNumInStock;
this.dblValueOfOneItem = doubleAddValueOfOneItem;
//Put items into warehouse A if appropriate.
if (intAddNumInStock < 25)
//Increment the warehouse A item count.
this.intWarehouseAItemCount = this.intWarehouseAItemCount + 1;
//Calculate the total value of warehouse A.
this.dblTotalValueA = this.dblTotalValueA + intAddNumInStock * doubleAddValueOfOneItem;
//Create the warehouse A array list.
this.createWareHouseA();
//Put items into warehouse B if appropriate.
if (intAddNumInStock >= 25)
if (intAddNumInStock < 75)
//Increment the warehouse B item count.
this.intWarehouseBItemCount = this.intWarehouseBItemCount + 1;
//Calculate the total value of warehouse B.
this.dblTotalValueB = this.dblTotalValueB + intAddNumInStock * doubleAddValueOfOneItem;
//Create the warehouse B array list.
this.createWareHouseB();
//Put items into warehouse C if appropriate.
if (intAddNumInStock >= 75)
//Increment the warehouse C item count.
this.intWarehouseCItemCount = this.intWarehouseCItemCount + 1;
//Calculate the total value of warehouse C.
this.dblTotalValueC = this.dblTotalValueC + intAddNumInStock * doubleAddValueOfOneItem;
//Create the warehouse C array list.
this.createWareHouseC();
//display helpful information.
System.out.println("!--------------------------------");
System.out.println("!" + addItemName + " is the item name.");
System.out.println("!" + addNumInStock + " is the number in stock.");
System.out.println("!" + addInitWarehouse + " is the initial warehouse.");
System.out.println("!" + addValueOfOneItem + " is the value of one item.");
System.out.println("!--------------------------------------------------");
//Increment the counters.
count++;
/**Create and write to the output file. */
try
//Use the output file specified by the user.
PrintWriter out = new PrintWriter(outputFile);
/**Write warehouse A details.*/
//Blank the first line.
out.println(" ");
//Write the array list for warehouse A.
out.println(warehouseAList);
//Write the amount of items in warehouse A.
out.println(intWarehouseAItemCount);
//Write the total value for warehouse A.
out.println(dblTotalValueA);
/**Write warehosue B details.*/
//Write the array list for warehouse B.
out.println(warehouseBList);
//Write the amount of items in warehouse B.
out.println(intWarehouseBItemCount);
//Write the total value for warehouse B.
out.println(dblTotalValueB);
/**Write warehouse C details.*/
//Write the array list for warehouse C.
out.println(warehouseCList);
//Write the amount of items in warehouse C.
out.println(intWarehouseCItemCount);
//Write the total value for warehouse C.
out.println(dblTotalValueC);
//Close the output file.
out.close();
catch (FileNotFoundException e)
System.out.println("Error: Unable to open file for reading.");
catch (IOException e)
System.out.println("Error: Cannot read from file.");
/**View the contents and the value of each warehouse.*/
System.out.println("!---------------Inventory Summary------------------");
System.out.println("!--------------------------------------------------");
System.out.println("!--------------------LEGEND:-----------------------");
System.out.println("!<item type>, <amount in stock>,<value of one item>");
System.out.println("!--------------------------------------------------");
System.out.println("!------------------Warehouse A:--------------------");
System.out.println("!--------------------------------------------------");
//Display Items in warehouse A.
System.out.println(warehouseAList);
//Total items in warehouse A.
System.out.println("Total items: " + intWarehouseAItemCount);
//Display total value of warehouse A.
System.out.println("Total value: " + "$" + dblTotalValueA);
System.out.println("!--------------------------------------------------");
System.out.println("!------------------Warehouse B:--------------------");
System.out.println("!--------------------------------------------------");
//Display Items in warehouse B.
System.out.println(warehouseBList);
//Total items in warehouse B.
System.out.println("Total items: " + intWarehouseBItemCount);
//Display total value of warehouse B.
System.out.println("Total value: " + "$" + dblTotalValueB);
System.out.println("!--------------------------------------------------");
System.out.println("!------------------Warehouse C:--------------------");
System.out.println("!--------------------------------------------------");
//Display Items in warehouse C.
System.out.println(warehouseCList);
//Total items in warehouse C.
System.out.println("Total items: " + intWarehouseCItemCount);
//Display total value of warehouse C.
System.out.println("Total value: " + "$" + dblTotalValueC);
/**Display a help message.*/
private void displayHelp()
System.out.println("!--------------------------------");
System.out.println("! General Help:");
System.out.println("!--------------------------------");
System.out.println("! ");
System.out.println("!'help' display this help message.");
System.out.println("!'Q!' quit this program.");
System.out.println("!--------------------------------");
System.out.println("! Input File Specific Commands:");
System.out.println("!--------------------------------");
System.out.println("! ");
System.out.println("!'F' <name> type F followed by the name of the " +
"file to be used for input.");
System.out.println("!---------------------------------------");
System.out.println("! Input From Keyboard Specific Commands:");
System.out.println("!---------------------------------------");
System.out.println("! ");
System.out.println("!'K' <number> type K followed by the number of " +
"items that will be added. ");
System.out.println("! ");
}Program file:
public class InventoryProg
public static void main(String[] args)
//Create a new Inventory object.
Inventory test = new Inventory();
//Execute the command interpreter.
test.cmdInterpreter();
}Right now I am stuck on this and I cannot progress any further until I figure out how to input the data in the text file back into a arraylist.
Thanks in advance.Thanks but I figured it out. Heres a sample of the code i used to solve my problem:
try
//Warehouse A BufferedReader.
BufferedReader inA = new BufferedReader(new FileReader(inputFileWarehouseA));
//Warehouse B BufferedReader.
BufferedReader inB = new BufferedReader(new FileReader(inputFileWarehouseB));
//Warehouse C BufferedReader.
BufferedReader inC = new BufferedReader(new FileReader(inputFileWarehouseC));
//Warehouse details BufferedReader.
BufferedReader inDetails = new BufferedReader(new FileReader(inputFileDetails));
//Will hold values in warehouse arraylists.
String lineA = null;
String lineB = null;
String lineC = null;
//Will hold the details of each warehouse.
String line1 = null;
String line2 = null;
String line3 = null;
String line4 = null;
String line5 = null;
String line6 = null;
//Get the item count and total value for each warehouse.
while(inDetails.readLine() != null)
line1 = inDetails.readLine();
line2 = inDetails.readLine();
line3 = inDetails.readLine();
line4 = inDetails.readLine();
line5 = inDetails.readLine();
line6 = inDetails.readLine();
/**Assign the item count and total value to warehouse A.*/
//Cast.
int intLine1 = Integer.valueOf(line1).intValue();
double dblLine2 = Double.valueOf(line2).doubleValue();
//Assign the values.
this.intWarehouseAItemCount = intLine1;
this.dblTotalValueA = dblLine2;
/**Assign the item count and total value to warehouse B.*/
//Cast.
int intLine3 = Integer.valueOf(line3).intValue();
double dblLine4 = Double.valueOf(line4).doubleValue();
//Assign the values.
this.intWarehouseBItemCount = intLine3;
this.dblTotalValueB = dblLine4;
/**Assign the item count and total value to warehouse C.*/
//Cast.
int intLine5 = Integer.valueOf(line5).intValue();
double dblLine6 = Double.valueOf(line6).doubleValue();
//Assign the values.
this.intWarehouseCItemCount = intLine5;
this.dblTotalValueC = dblLine6;
/**Put the items back into the warehouses arraylists. */
//Add items to warehouse A.
while((lineA = inA.readLine()) != null)
warehouseAList.add(lineA);
//Add items to warehouse B.
while((lineB = inB.readLine()) != null)
warehouseBList.add(lineB);
//Add items to warehouse C.
while((lineC = inC.readLine()) != null)
warehouseCList.add(lineC);
}(this isn't the whole try statement its pretty long) -
How to upload data into a database from a csv file in a jsp app?
I can write a HTML form to let users to post a csv file and store it in the web server, then how could I process the file to load the data into a View Obj or an Entity Obj without manually parsing the csv files? Any jsp or java code samples that will do something like the "sqlload" in sqlplus?
I'm using JDev 3.1.1.2. Thanks.Navy_Coder wrote:
6 zebras.But you must marry his eldest daughter as well, for that dowry. -
How to store data in a file without using DB
Hi all
I want to develop a small application that could contain at most 10000 records, so if it is possible I want to store the data in a file, therefore the installation of the application can be simplified and the users don't need to add a ODBC dataSource in the control panel before running the program.
If the above is not possible. Does anyone know how to use Java to programmatically add a ODBC dataSrouce in the control panel in the Windows Platform?
Thank you very much !
Kind Regards
Edmond1 ) Save the records into a vector and write it to a file. You will have to load all the records when you read the file though.
2 ) Use a dsn-less connection. You do not need to have a dsn set up and you can access a file using the bridge driver:
url = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+file.getPath();
//Obtain the driver for the
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Create the connection
con = DriverManager.getConnection(url, "", "");
//Ensure that the connection allows two way commands
if (con.isReadOnly()) con.setReadOnly(false);
//Create the statement to be executed
stmt = con.createStatement();
//execute the select statement
ResultSet rs = stmt.executeQuery("SELECT * FROM \"Sheet1$\"");
This should work, let me know if it dwosnt -
Hi
I want to write data from a string into a file. I am created a directory and a .doc file . But when i write this data from a string into .doc file , its give an error : File not found exception
But, when i check in my directory, a file is created with blank.
My code is:
import java.io.*;
import java.util.*;
import java.lang.*;
class createFile {
public static void main(String[] args) {
try {
String mss = "This is for dedo";
FileInputStream fis;
FileOutputStream fos;
File file = new File("C:\\JD\\m4.rtf");
// Create file if it does not exist
boolean success = file.createNewFile();
success = true;
if (success) {
System.out.println("suc");
fis = new FileInputStream(mss);
System.out.println(fis);
fos = new FileOutputStream(file);
int c;
while ((c = fis.read()) != -1) {
fos.write(c);
System.out.println("mss");
fis.close();
fos.close();
System.out.println("created");
// File did not exist and was created
} else {
// File already exists
} catch (IOException e) {
System.out.println(e);
regards
madhuInputStream inputStream = new ByteArrayInputStream(mss.getBytes());Use this to push into the file>
Ummm.... no. InputStreams are for reading, not for writing.
Anyway, OP, you're making a mistake. You're trying to open a stream to a file called "This is for dedo". Use FileOutputStream(File file) constructor or FileOutputStream(String pathToFile). You can then wrap that stream with a PrintWriter or whatever you need. -
How to insert data into Oracle db from MySQL db through PHP?
Hi,
I want to insert my MySQL data into Oracle database through PHP.
I can access Mysql database using mysql_conect() & Oracle database using oci_connect() through PHP.
Now How can I insert my data which is in MySQL into Oracle table. Both table structure are exactly same.
So I can use
insert into Oracle_Table(Oracle_columns....) values(Select * from MySQL_Table);
But again problem is I can't open both connections at the same time.
So has anyone done this before or anyone having any other idea..
Plz guide me...You can do it if you setup a ODBC Gateway between MYSQL and Oracle DB. Then you can directly read from MySQL table using DB links and insert into Oracle table in one single SQL Statement.
Otherwise you need to fetch the data from MySQL Into variables in your PHP Program and then insert into Oracle after binding the variables to the insert statement for Oracle. Hope that is clear enough.
Regards
Prakash -
How to input data into Pdf file
I am not too sure if I am posting my question in the right forum.
I would like to know what version of Adobe acrobat can allow me to create a document, where clients can input data into it?
Here is an online example
http://www.uscis.gov/files/form/N-400.pdf
Thanks.
OceansIf your users will be using Reader and you want your users to be able to save the form or email it, you will need to apply 'Extended Form Rights' (version 8 Provessional or Version 9 Standard or better) and for signatures you will need to apply 'Signature Rights' using an Adobe server product.
Maybe you are looking for
-
I KEEP GETTING AN ERROR MESSAGE STATING THAT MY MIDI HAS TIMED OUT, HOW DO I RESOLVE THIS?
-
Hi guys, I have a requirement in Automatic payment program. Say we have 3 house banks and a payment method C. Right now when I run F110 , the system will pick up the house bank from the ranking order. But I want to give the user the option to select
-
Hi, I'm passing some binary MIME attachment to OSB Proxy service. OSB proxy service is able to pick attachment & converting to binary to text through Messaging service. Now I want to pass this attachment to BPEL , which will write at some location...
-
How to protect my iphone from scratched
How to protect my iphone from scratched
-
Why isnt my phone number it 'Recieve At' for iMessage
Please help! i can onlky seem to get me email address in my 'Receive At' section on iMessage... there is no option to add a phone number...