How to send the file contents in the application server to ftp server
Hi,
how to send the file contents in the application server to ftp server.
regards,
sree
Test SAP FTP functions
DATA: BEGIN OF MTAB_DATA OCCURS 0,
LINE(132) TYPE C,
END OF MTAB_DATA.
DATA: MC_PASSWORD(20) TYPE C,
MI_KEY TYPE I VALUE 26101957,
MI_PWD_LEN TYPE I,
MI_HANDLE TYPE I.
START-OF-SELECTION.
MC_PASSWORD = 'password'.
DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN.
*-- FTP_CONNECT requires an encrypted password to work
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD MC_PASSWORD ID 'KEY' FIELD MI_KEY
ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD MC_PASSWORD
ID 'DSTLEN' FIELD MI_PWD_LEN.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
USER = 'userid'
PASSWORD = MC_PASSWORD
HOST = 'servername'
RFC_DESTINATION = 'SAPFTP'
IMPORTING
HANDLE = MI_HANDLE
EXCEPTIONS
NOT_CONNECTED = 1
OTHERS = 2.
CHECK SY-SUBRC = 0.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = MI_HANDLE
COMMAND = 'dir'
TABLES
DATA = MTAB_DATA
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF SY-SUBRC = 0.
LOOP AT MTAB_DATA.
WRITE: / MTAB_DATA.
ENDLOOP.
ELSE.
do some error checking.
ENDIF.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
HANDLE = MI_HANDLE
EXCEPTIONS
OTHERS = 1.
Execute external commands (FTP Scripts)
The following code shows the syntax of the FM 'SXPG_COMMAND_EXECUTE'. You pass it the external command created within transaction SM69 and it will execute it.
DATA: ld_comline
LIKE sxpgcolist-name,
ld_param LIKE sxpgcolist-parameters,
ld_status LIKE extcmdexex-status,
ld_output LIKE btcxpm OCCURS 0 WITH HEADER LINE,
ld_subrc LIKE sy-subrc.
REFRESH ld_output.
MOVE 'FTP_DATA_IN' to ld_comline. "Maintained using trans SM69
Execute external command, contained in 'ld_comline'
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = ld_comline
additional_parameters = ld_param "Params passed to script
operatingsystem
= 'UNIX'
IMPORTING
status = ld_status
TABLES
exec_protocol = ld_output
EXCEPTIONS
no_permission
= 1
command_not_found
= 2
parameters_too_long
= 3
security_risk
= 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry
= 13
jobcount_generation_error
= 14
OTHERS
= 15.
IF sy-subrc NE 0.
ENDIF.
Similar Messages
-
How to view the file content from the directory? getting Error:ORA-21560
SQL> create directory READ_LOB_DIR as 'D:\Prj\Comm\Data';
CREATE OR REPLACE Procedure READ_FILE_LOB IS
-- Input Directory as specified in create directory
l_dir CONSTANT VARCHAR2(30) := 'READ_LOB_DIR';
-- Input File which is read word by word
l_fil CONSTANT VARCHAR2(30) := 'testfile.txt';
-- Separator Character between words is a BLANK (ascii = 32)
l_seb CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(32));
-- Character at the end of the file is NEWLINE (ascii = 10)
l_sen CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(10));
-- Pointer to the BFILE
l_loc BFILE;
-- Current position in the file (file begins at position 1)
l_pos NUMBER := 1;
-- Amount of characters have been read
l_sum BINARY_INTEGER := 0;
-- Read Buffer
l_buf VARCHAR2(500);
-- End of the current word which will be read
l_end NUMBER;
-- Return value
l_ret BOOLEAN := FALSE;
BEGIN
-- Mapping the physical file with the pointer to the BFILE
l_loc := BFILENAME(l_dir, l_fil);
-- Check if the file exists
l_ret := DBMS_LOB.FILEEXISTS(l_loc) = 1;
IF (l_ret) THEN
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' exists');
-- Open the file in READ_ONLY mode
DBMS_LOB.OPEN(l_loc, DBMS_LOB.LOB_READONLY);
LOOP
-- Calculate the end of the current word
l_end := DBMS_LOB.INSTR(l_loc, l_seb, l_pos, 1);
-- Process end-of-file
IF (l_end = 0) THEN
l_end := DBMS_LOB.INSTR(l_loc, l_sen, l_pos, 1);
l_sum := l_end - l_pos - 1;
DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
EXIT;
END IF;
-- Read until end-of-file
l_sum := l_end - l_pos;
DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
l_pos := l_pos + l_sum + 1;
END LOOP;
DBMS_LOB.CLOSE(l_loc);
ELSE
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' does not exist');
END IF;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error:' || SQLERRM);
DBMS_LOB.CLOSE(l_loc);
END;
The Text file content is...
Copyright 1996,2001 Oracle Corporation. All Rights Reserved
This file contains installation instructions for installing the
Oracle8 ODBC Driver software.
It is divided into four parts:
o Part I: Summary of systems supported by Oracle8 ODBC client
software
Lists the platforms on which the Oracle8 ODBC Client software can
be installed.
o Part II: Oracle8 ODBC Driver software.
Describes the files, and installation prerequisites for the Oracle8
ODBC driver software.
o Part III: Exploding the kit onto your system
Describes how to explode the kit onto your system hard drive.
o Part IV: Installation Instructions
Describes how to install the Oracle8 ODBC driver.
Part I: Systems supported by the Oracle8 client software
You can install the ODBC client software on any of the following systems:
o Windows 2000
o Windows NT X86
o Windows 95
o Windows 98
The Oracle8 ODBC Driver provides support for ODBC connections
from Windows 2000, Windows NT, Windows 95, and Windows 98 systems
to Oracle databases.
o Part II: Oracle8 ODBC Driver software.
Refer to the following files for information about the Oracle8 ODBC Driver:
LICENSE.TXT - Oracle8 ODBC Driver License Agreement. Read carefully
before installing and/or using this product. Enclosed in
your software distribution kit.
SQORA.HLP - A Window's Help file which is the primary reference
manual for the Oracle8 ODBC Driver.
ODBCRelnotes.WRI - The release notes for the Oracle8 ODBC Driver
which contains information which may have not been
included in the Help file.
Installation Prerequisites
See the Oracle8 ODBC Driver release notes (ODBCRelnotes.WRI),
for a complete list of software products required and their versions.
Time Required
The installation of the Oracle8 ODBC Driver takes approximately 5
minutes. The actual time may be shorter or longer, depending upon
your hardware configuration.
Disk Space Required
The Oracle8 ODBC driver installation requires approximately 2
megabytes of available storage space. The space required depends upon
what files you already have installed. The installation procedure
checks to see if you have enough available disk space. If you do not,
the installation fails.
Part III: Exploding the Kit onto your system
Expand the self-extracting archive file onto your hard drive.
C:\> ORA8174.EXE
Part IV: Installation Instructions
Oracle8 ODBC Driver 8.1.7.4.0
This section assumes the following:
1. MS Windows 2000, Windows NT, Windows 95 or Windows 98 is running.
2. Oracle Universal Installer shipping with 8.1.7 has already been
installed on your system.
3. Part III has been completed.
Software fixes:
Refer to release notes (ODBCRelnotes.wri) for a complete list of
Software fixes.
Installation Instructions
Once the self-extracting archive file ORA8174.EXE has been
exploded it will create an installable directory structure
onto your hard drive. Run the Oracle Universal Installer from
your local drive.
1. On the screen "File Locations" use the "Browse" button of
the source path to choose the file 'products.jar' from the
folder that ORA8174.EXE was extracted to. Choose 'Next'.
2. You will receive a warning that some of the dependencies of
this product are not found in the staging area. This warning
is OK. The ODBC driver depends on the Net8 Client being already
installed on the system. Answer 'Yes' to continue.
Oracle is a registered trademark of Oracle Corporation.
Microsoft, MS are registered trademarks of Microsoft Corporation.
Microsoft Windows, Windows NT, Windows 95, Windows 98 and Open Database
Connectivity are trademarks of Microsoft Corporation.
All other trademarks and registered trademarks are the property
of their respective owners.
The output was...
File testfile.txt in Directory READ_LOB_DIR exists
Copyright
1996,2001
Oracle
Corporation.
All
Rights
Reserved
This
file
contains
installation
instructions
for
installing
the
Oracle8
ODBC
Driver
software.
It
is
divided
into
four
parts:
o
Part
I:
Summary
of
systems
supported
by
Oracle8
ODBC
client
Error:ORA-21560: argument 2 is null, invalid, or out of range
I want to diplay/view as per file content format from the file under that specified directory.
Have any other method / any help or suggestions would be really appreciated.I changed the code like...
CREATE OR REPLACE Procedure READ_FILE_LOB_tmp IS
-- Input Directory as specified in create directory
l_dir CONSTANT VARCHAR2(30) := 'READ_LOB_DIR';
-- Input File which is read word by word
l_fil CONSTANT VARCHAR2(30) := 'testfile.txt';
-- Separator Character between words is a BLANK (ascii = 32)
l_seb CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(32));
-- Character at the end of the file is NEWLINE (ascii = 10)
l_sen CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(10));
-- Pointer to the BFILE
l_loc BFILE;
-- Current position in the file (file begins at position 1)
l_pos NUMBER := 1;
-- Amount of characters have been read
l_sum BINARY_INTEGER := 0;
-- Read Buffer
l_buf VARCHAR2(4000);
-- End of the current word which will be read
l_end NUMBER;
-- Return value
l_ret BOOLEAN := FALSE;
BEGIN
-- Mapping the physical file with the pointer to the BFILE
l_loc := BFILENAME(l_dir, l_fil);
-- Check if the file exists
l_ret := DBMS_LOB.FILEEXISTS(l_loc) = 1;
IF (l_ret) THEN
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' exists');
-- Open the file in READ_ONLY mode
DBMS_LOB.OPEN(l_loc, DBMS_LOB.LOB_READONLY);
LOOP
-- Calculate the end of the current word
l_end := DBMS_LOB.INSTR(l_loc, l_sen, l_pos, 1);
-- Process end-of-file
IF (l_end = 0) THEN
EXIT;
END IF;
-- Read until end-of-file
l_sum := l_end - l_pos;
DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
l_pos := l_pos + l_sum + 1;
END LOOP;
DBMS_LOB.CLOSE(l_loc);
ELSE
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' does not exist');
END IF;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error:' || SQLERRM);
DBMS_LOB.CLOSE(l_loc);
END;
Now its working fine with one addtional line...
The file content is...
This is My Content
This is My Content
This is My Content
This is My Content
This is My Content
But The output was...
File testfile.txt in Directory READ_LOB_DIR exists
This is My Content
This is My Content
This is My Content
This is My Content
This is My Content
here, i want to delete that additonal line...? -
Please tell me How to send excel file content to MAILBOX
Hello ,
Can anybody tell me how to send Excel file data to MailboxHi,
Check this sample code.
INITIALIZATION .
CLASS cl_abap_char_utilities DEFINITION LOAD.
gf_etb = cl_abap_char_utilities=>horizontal_tab. "For horrizontal tab
gf_cr = cl_abap_char_utilities=>cr_lf. "For enter
gf_lf = cl_abap_char_utilities=>newline. "For new line
Declaration
DATA: lwa_hd_change TYPE sood1,
lt_objcont TYPE STANDARD TABLE OF soli,
lwa_objcont TYPE soli,
lt_receivers TYPE STANDARD TABLE OF soos1,
lwa_receivers TYPE soos1 ,
lt_att_cont TYPE STANDARD TABLE OF soli,
lwa_att_cont TYPE soli,
lt_packing TYPE STANDARD TABLE OF soxpl,
lwa_packing TYPE soxpl,
lf_sent TYPE sonv-flag,
lf_size TYPE i.
CONSTANTS: lc_obj(11) TYPE c VALUE 'BOMSouthco',
lc_desc(20) TYPE c VALUE 'BOM Download',
lc_lang(1) TYPE c VALUE 'E',
lc_raw(3) TYPE c VALUE 'RAW',
lc_net(1) TYPE c VALUE 'U',
lc_mail(4) TYPE c VALUE 'MAIL',
lc_xls(3) TYPE c VALUE 'XLS',
lc_ext(3) TYPE c VALUE 'EXT'.
Passing values to the strutures used in SO_OBJECT_SEND function module
lwa_hd_change-objla = lc_lang.
lwa_hd_change-objnam = lc_obj.
lwa_hd_change-objdes = lc_desc.
lwa_hd_change-objlen = 255.
lwa_objcont-line = text-t29.
APPEND lwa_objcont TO lt_objcont.
CLEAR lwa_objcont.
lwa_receivers-recextnam = text-t31.
lwa_receivers-recesc = lc_net.
lwa_receivers-sndart = lc_mail.
lwa_receivers-sndex = 'X'.
lwa_receivers-sndpri = 1.
lwa_receivers-mailstatus = 'E'.
APPEND lwa_receivers TO lt_receivers.
CLEAR lwa_receivers.
lwa_receivers-recextnam = text-t30.
lwa_receivers-recesc = lc_net.
lwa_receivers-sndart = lc_mail.
lwa_receivers-sndex = 'X'.
lwa_receivers-sndpri = 1.
lwa_receivers-mailstatus = 'E'.
APPEND lwa_receivers TO lt_receivers.
CLEAR lwa_receivers.
Passing values for the attachment file
LOOP AT gt_output INTO gwa_output.
CONCATENATE gf_lf gwa_output-matnr gf_etb gwa_output-idnrk gf_etb
gwa_output-type gf_etb gwa_output-menge gf_etb
gwa_output-meins gf_etb gwa_output-comp gf_etb
INTO lwa_att_cont-line.
APPEND lwa_att_cont TO lt_att_cont.
CLEAR lwa_att_cont.
ENDLOOP.
CHECK lt_att_cont IS NOT INITIAL.
DESCRIBE TABLE lt_att_cont LINES lf_size.
lwa_packing-transf_bin = ' '.
lwa_packing-head_start = 1.
lwa_packing-head_num = 0.
lwa_packing-body_start = 1.
lwa_packing-body_num = lf_size.
lwa_packing-file_ext = lc_xls.
lwa_packing-objlen = lf_size * 255.
lwa_packing-objtp = lc_ext.
lwa_packing-objdes = lc_desc.
lwa_packing-objnam = lc_obj.
APPEND lwa_packing TO lt_packing.
CLEAR lwa_packing.
CHECK gf_error IS NOT INITIAL. "Check if unix file is written
FM to send email to the intended recipients
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = lwa_hd_change
object_type = lc_raw
IMPORTING
sent_to_all = lf_sent
TABLES
objcont = lt_objcont
receivers = lt_receivers
packing_list = lt_packing
att_cont = lt_att_cont
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
originator_not_exist = 20
x_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE s004 WITH text-t34.
ENDIF.
COMMIT WORK.
Reward if helpful.
Regards,
Ramya -
How to read text file content in portal application?
Hi,
How do we read text file content in portal application?
Can anyone forward the code to do do?
Regards,
AnaghaCheck the code below. This help you to know how to read the text file content line by line. You can display as you require.
IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
IResourceContext resourceContext = new ResourceContext(user);
String filePath = "/documents/....";
RID rid = RID.getRID(filePath);
IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);
InputStream inputStream = resource.getContent().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
while(line!=null) {
line = reader.readLine();
//You can append in string buffer to get file content as string object//
Regards,
Yoga -
Send text file content as the body of an email using Send-MailMessage
I am taking the last 8 lines of a bunch of robocopy logs and bunching them together.
Get-ChildItem -Filter *.log | ForEach {
$a += Get-Content $_.Name | Select -Last 8
$a += Write-output ' '`r
$a += Write-Output '------------------------------------------------------------------------------'`r
I then wanted to use this as the body of an email (send-mailmessage). It all works but the formatting is lost in the email. I've tried using Out-String and ConvertTo-HTML with little luck.
If I look at $a in the above it looks fine in the PowerShell console it's just lost when it reaches my inbox.
I am using v2 of PowerShell and sadly can't upgrade it.The issue isn't that part. It's the content of the log files that loses its formatting.
$a += Get-Content $_.Name | Select -Last 8 -
Records are missing in the File which XI has placed in Target FTP server
Hi All,
I have a scenario where in XI is transfering the files from ECC to Target System . No transformation required here . I am using AAE to run this scenario.
Issue i am facing here is that i can see few records missing in the File which XI had placed in the Target system FTP server . Same file if i check it in archive folder of ECC (which XI has archived after picking the file), complete set of records are present for the same file.
Need your inputs please....
Note : XI is using AAE to transfer the files and no mapping . Also i tried to check out the audit logs in the channel monitoring . Unforutanely i was not able to see the logs to check the bytes that was transferred while readng and writing the file . Sometimes i have faced audit logs issue in PI 7.1
Regards
Vinay P.Please use temporary name scheme
http://help.sap.com/saphelp_nwpi711/helpdata/en/44/6830e67f2a6d12e10000000a1553f6/content.htm
hope this helps
regards
Ninad -
How to send a file downloded either to application or presentation server
Hi guys,
I had a requirement...
my program should first download a flat-file to application/presentation server and latter send this file as an attachment via email to recipient..
can you guys help me....
cheers,
HarishHi Harish,
for the download to presentation server
cl_gui_frontend_services=>gui_download.
To download the file to presentation server use
command open dataset
To transfer the file you have to use command TRANSFER
To send the file as attachment you use Function Module
SO_NEW_DOCUMENT_ATT_SEND_API1.
Make sure you commit rsconn01 after calling SO_NEW_DOCUMENT_ATT_SEND_API1 only this will trigger the sending of your mail.
Kind regards Henner -
How can I convert my specific file content in the Receiver Adapter(XI 7.0)?
Hi all,
I have a document structure as below:
<MT_MATERIAL>
<MATERIAL>
<WERKS>1000</WERKS>
<MATNR>HAD_00001</MATNR>
<MAKTX>CHEMICAL MATERIAL</MAKTX>
</MATERIAL>
</MT_MATERIAL>
This document structure is the file content in the Receiver Adapter (File Adapter). In the 'Content Conversion' tab of File Adapter of Communication Channel 'CC_OUT_MATERIAL_FILE', I have configured the parameters as below:
Recordset Structure: MATERIAL
MT_MATERIAL.fieldSeparator: '
MT_MATERIAL.endSeparator: 'nl'
MATERIAL.fieldSeparator: '
MATERIAL.endSeparator: 'nl'
*.fieldSeparator: ,
But, this Communication Channel 'CC_OUT_MATERIAL_FILE' (in the Runtime WorkBench/Component Monitoring/Adapter Engine/Communication Channel Monitoring) is error with the error message as below:
Conversion initialization failed: java.lang.Exception: java.lang.Exception: Error(s) in XML conversion parameters found: Parameter '.fieldFixedLengths' or '.fieldSeparator' is missing
Could anyone please help me to correct this error, how should i configure the parameters in the 'Content Conversion' tab?
Thanks a lot in advance,
Vinh VoHi Vinho,
Introduction to simple(File-XI-File)scenario and complete walk through for starters(Part1)
Introduction to simple (File-XI-File)scenario and complete walk through for starters(Part2)
Have a look at the this blog by Arpit Seth ... its all about FCC at receiver side...
File Receiver with Content Conversion
Also have a look at this thread.. might be helps you....
RECEIVER file CONTENT CONVERSION
Above links be helpful.
Regards,
Jayasimha Jangam -
How to send a file to a web service
I am developing a web service application which needs to accept a CAD model as input. Would any one tell me how to send a file from a client application to service provider.
thanks in advanceYou can use mime encoding inside your SOAP request, something like this:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<data>
<file>
<name>filename.zip</name>
<content>FVberI0XlJincJEGmcbVyMOGpdWGl1bYB2r1y2vYicHqq0WYuergigzYB20GvMLZ
Ag9YicHozwLSieOUieDLzgrLCZKncI9dCMvHDg9YicGPdqOVu3vIAMvJDcaOkq0kl0TLExDVCMrZ
DwfSifnVzNr3yxjLkq0kl1rPDgXLicHdB252zxj0zwqGzNjVBsbmyxnLCKPLDcbqq0WPdqOVqxv0
l1jVB3qGmIaWifiGl0LUzM8GmsaWifiGpJ4ncNn0yxj0EhjLzG0kndyYzxiGpdWGl1nPEMuGmJyG
mdaWndiZmYaWmdaWmcbUdqOWmdaWmda0ndi1idaWmdaWig4ncNrYywLSnG0kjsvft0yncG==
</content>
</file>
</data>
</soap:Body>
</soap:Envelope>This can even be accomplished from within Pl/Sql. Otherwise you can use the WS-Attachment feature which is (I think) not yet supported by Oracle.
Regards,
Michiel -
I went through all the steps to try to resolve getting the message in a box every time i try to send an e-mail. What next ?
Message is " A copy has been placed in your
Outbox. Sending the message content to the server failed."
Any assistance would be greatly appreciated. My internet works fine as I can send e-mails from my Yahoo account on my MAC no problem.
Address is fine etc.How long has it been going on? I've had my yahoo mess up and if i wait a bit it resolves itself. Yahoo is doing something with their servers and it messes with your mail if your mail happens to be on one of those servers.
-
How to download a file/contents through a session bean to the bean client
Hi All,
I'm a newbie to enterprise beans and facing a problem. I have a requirement where an excel file saved on the server will be a accessed by a session bean and return it to the bean client (developed in swing). Client will display the file contents, user edits the contents and saves. Pressing the save button will save the excel on the server again using the same session bean.
As far as displaying the contents of excel on the form/panel is concerned I have developed this part and able to load files and save them on my local machine.
But my main requirement is to load it through Session Bean and then save it back on the server. An EJB 2.0 code snippet addressing this part would be a great help.
Thanks,and where's the problem?
I see 2 EJB calls, one to retrieve the data and another one to send it back to the server.
That's the simplest scenario, easy to implement using a stateless session bean (though if you want to prevent concurrent modification of the file there's a bit more work to do, like keeping a record of open files).
A more complex solution would have the client send only the changes to the file (for network performance reasons maybe) and have the EJB merge those in some way with the original document.
Complex, possibly error prone, probably not worth the effort.
First scenario should pose no problem if you're familiar with Java and have a passing familiarity with EJB. -
How to write the JTables Content into the CSV File.
Hi Friends
I managed to write the Database records into the CSV Files. Now i would like to add the JTables contend into the CSV Files.
I just add the Code which Used to write the Database records into the CSV Files.
void exportApi()throws Exception
try
PrintWriter writing= new PrintWriter(new FileWriter("Report.csv"));
System.out.println("Connected");
stexport=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rsexport=stexport.executeQuery("Select * from IssuedBook ");
ResultSetMetaData md = rsexport.getMetaData();
int columns = md.getColumnCount();
String fieldNames[]={"No","Name","Author","Date","Id","Issued","Return"};
//write fields names
String rec = "";
for (int i=0; i < fieldNames.length; i++)
rec +='\"'+fieldNames[i]+'\"';
rec+=",";
if (rec.endsWith(",")) rec=rec.substring(0, (rec.length()-1));
writing.println(rec);
//write values from result set to file
rsexport.beforeFirst();
while(rsexport.next())
rec = "";
for (int i=1; i < (columns+1); i++)
try
rec +="\""+rsexport.getString(i)+"\",";
rec +="\""+rsexport.getInt(i)+"\",";
catch(SQLException sqle)
// I would add this System.out.println("Exception in retrieval in for loop:\n"+sqle);
if (rec.endsWith(",")) rec=rec.substring(0,(rec.length()-1));
writing.println(rec);
writing.close();
}With this Same code how to Write the JTable content into the CSV Files.
Please tell me how to implement this.
Thank you for your Service
JofinHi Friends
I just modified my code and tried according to your suggestion. But here it does not print the records inside CSV File. But when i use ResultSet it prints the Records inside the CSV. Now i want to Display only the JTable content.
I am posting my code here. Please run this code and find the Report.csv file in your current Directory. and please help me to come out of this Problem.
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
public class Exporting extends JDialog implements ActionListener
private JRadioButton rby,rbn,rbr,rbnore,rbnorest;
private ButtonGroup bg;
private JPanel exportpanel;
private JButton btnExpots;
FileReader reading=null;
FileWriter writing=null;
JTable table;
JScrollPane scroll;
public Exporting()throws Exception
setSize(550,450);
setTitle("Export Results");
this.setLocation(100,100);
String Heading[]={"BOOK ID","NAME","AUTHOR","PRICE"};
String records[][]={{"B0201","JAVA PROGRAMING","JAMES","1234.00"},
{"B0202","SERVLET PROGRAMING","GOSLIN","1425.00"},
{"B0203","PHP DEVELOPMENT","SUNITHA","123"},
{"B0204","PRIAM","SELVI","1354"},
{"B0205","JAVA PROGRAMING","JAMES","1234.00"},
{"B0206","SERVLET PROGRAMING","GOSLIN","1425.00"},
{"B0207","PHP DEVELOPMENT","SUNITHA","123"},
{"B0208","PRIAM","SELVI","1354"}};
btnExpots= new JButton("Export");
btnExpots.addActionListener(this);
btnExpots.setBounds(140,200,60,25);
table = new JTable();
scroll=new JScrollPane(table);
((DefaultTableModel)table.getModel()).setDataVector(records,Heading);
System.out.println(table.getModel());
exportpanel= new JPanel();
exportpanel.add(btnExpots,BorderLayout.SOUTH);
exportpanel.add(scroll);
getContentPane().add(exportpanel);
setVisible(true);
public void actionPerformed(ActionEvent ae)
Object obj=ae.getSource();
try {
PrintWriter writing= new PrintWriter(new FileWriter("Report.csv"));
if(obj==btnExpots)
for(int row=0;row<table.getRowCount();++row)
for(int col=0;col<table.getColumnCount();++col)
Object ob=table.getValueAt(row,col);
//exportApi(ob);
System.out.println(ob);
System.out.println("Connected");
String fieldNames[]={"BOOK ID","NAME","AUTHOR","PRICE"};
String rec = "";
for (int i=0; i <fieldNames.length; i++)
rec +='\"'+fieldNames[i]+'\"';
rec+=",";
if (rec.endsWith(",")) rec=rec.substring(0, (rec.length()-1));
writing.println(rec);
//write values from result set to file
rec +="\""+ob+"\",";
if (rec.endsWith(",")) rec=rec.substring(0,(rec.length()-1));
writing.println(rec);
writing.close();
catch(Exception ex)
ex.printStackTrace();
public static void main(String arg[]) throws Exception
Exporting ex= new Exporting();
}Could anyone Please modify my code and help me out.
Thank you for your service
Cheers
Jofin -
How to send a mail by ckicking the button using java
hi,
how to send a mail by clicking the button (like payroll silp in that contain one button if we click that it autometically go through the mail as a attachment) pls frd to me my gmail is [email protected]Hi,
It seems we are doing the homework for you; to make you start with something; look at the sample code below and try to understand it first then put the right values
to send an email with an attachement.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Main {
* @param args
public static void main(String[] args) {
// Create the frame
String title = "Frame Title";
JFrame frame = new JFrame(title);
// Create a component to add to the frame
JComponent comp = new JTextField();
Action action = new AbstractAction("Button Label") {
// This method is called when the button is pressed
public void actionPerformed(ActionEvent evt) {
System.out.println("sending email with attachment");
sendEmail();
// Create the button
JButton button = new JButton(action);
// Add the component to the frame's content pane;
// by default, the content pane has a border layout
frame.getContentPane().add(comp, BorderLayout.SOUTH);
frame.getContentPane().add(button, BorderLayout.NORTH);
// Show the frame
int width = 300;
int height = 300;
frame.setSize(width, height);
frame.setVisible(true);
protected static void sendEmail() {
String from = "me@localhost";
String to = "me@localhost";
String subject = "Important Message";
String bodyText = "This is a important message with attachment";
String filename = "c:\\tmp\\message.pdf";
Properties properties = new Properties();
properties.put("mail.stmp.host", "localhost");
properties.put("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(properties, null);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(
to));
message.setSubject(subject);
message.setSentDate(new Date());
// Set the email message text.
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);
// Set the email attachment file
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource(filename) {
@Override
public String getContentType() {
return "application/octet-stream";
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}The sample above is not ideal so you need to go through it and start to ask me some questions if you have
Let me know if you miss something
Regards,
Alan Mehio
London,UK -
How to get the file path in adf application
hii all,
i have a txt file that i am using in my adf application,
i am passing this txt file through a File Reader, for which i have to mention the file path.
The file is in web-content and when i am hard coding the complete file path i.e C:/JDeveloper/myApp/ViewController/public_html/log.txt
the application is working fine when run on integrated weblogic server.
My requirement is to access this file without giving the static file path, as in case i have to use this application on any other machine..
for that how to mention the file path-
i tried using FacesContext to get the context path :-
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
which gives me
\myApp-ViewController-context-root
after appending public_html\log.txt
I am using the following path to access the file :-
\myApp-ViewController-context-root\public_html\log.txt
again i am getting the java.io.FileNotFoundException
Does anyone know how to use file from inside the web-content without giving the complete path..???
ThanksHi,
If you put your file under public_html folder, you can use this code to access the file:
For example file is : log.txt
FacesContext.getCurrentInstance().getExternalContext().getRealPath('/log.txt').toString().trim();
Thanks.
- LSR -
How do I share files uploaded into the Creative Cloud with other creative cloud members?
How do I share files uploaded into the Creative Cloud with other creative cloud members?
Should be easy. Try this...
In Thumbnails view, click the little triangle (pointing downward) in the lower-right corner of the asset you want to share.
In the blue icon bar that appears, click the Share icon (the third icon from the left, just right of the trash icon). The Share dialog should pop up.
In the Share dialog, enter the email address of the person with whom you want to share the asset, then click the Send Email button - they'll receive an email with a link to your asset. OR
You can also copy a link to the asset and then paste that into your own email client if you prefer. To do that, click the Link icon (looks like a "chain", and is to the right of the email "envelope" icon) - then click the Copy Link button.
Note that the Share options won't be available if your asset is set to "Private" - you can control whether an asset can be viewed (or downloaded) by others by clicking the Public/Private control (green or red "lock" icon).
You can also access the same Share controls if you click on the file to see it one-up (you can do this from either Thumbnails view or List view); click the Share icon near the upper right corner of the browser window (to the right of the asset name).
Hope that helps.
Maybe you are looking for
-
I'm getting this error when I try to install the newest version of Itunes. I have tried so many things. Please help. installer has insufficinent privileges to access this directory c:\program files\ipod\bin log on as administrator
-
Hello XI Experts Could anyone please provide more information about how to use the Batch mode in JDBC adapter. I would be sending about 200,000 records from abap proxy to oracle. Is it better to adopt the batch mode approach or the splitting of data
-
Ok now I am getting somewhere with OWB. Well all thanks to you guys for helping me out with my questions. Anyway now I am facing an issue I want to create the output files with today's file name. I mean if i am running the mapping on the 20th of Octo
-
Trying to fix ipod. Process of elimination replacing parts...
HI, I'm currently trying to fix an iPod colour (4th gen). It will not boot up normally, only ever getting to the Apple logo. It shows, at different times, both the sad ipod and the folder icon. I have replaced the hard drive and the logic board. Runn
-
I've downloaded Creative Cloud and the App for Photoshop and updated the app -- but there's no way to click on the application to use it! I seem to be missing something ... I don't know how to get into it to work on photos ...