Brief Introduction
Two days ago, a servlet-based file upload page was developed for the project. Oracle Jserv was used on the front-end to process the servlet page on the Apache server. The file upload function was implemented based on MultipartRequest in the java open source component of oreilly. The background is to use shell + sqlloader to import the uploaded files to the temporary table in csv format, and call concurrent requests to process the temporary table data to the Oracle formal table. Some problems have been solved and shared.
1. How to Make the servlet output correctly display Chinese characters?
Use new String () and getBytes to convert a String to a specified character set. Sample Code:
String str = "Chinese ";
Str = new String (str. getBytes ('iso-8859-1 '), 'gbk ');
2. How to add a group or batch ID to the imported data before inserting the table?
1) Use sqlplus in shell to retrieve a sequence as a group ID:
SQLRET = 'sqlplus-s $ {USER_PASSWORD} <SQLEND
SET HEADING OFF
SELECT TABLE_S.NEXTVAL
From dual;
EXIT
SQLEND | awk '{print $0 }''
BATCH_ID = 'echo $ {SQLRET }'
2) edit the uploaded csv file and insert the batch ID for each row in the file:
Cat $ csv_file | while read work
Do
Echo $ BATCH_ID, $ work >>$ TMP_FILE
Done
3. How can I determine whether a file is a text file or a binary file?
Using the file command, if it is a text file, the output of the file command will contain the words "text". Based on this, we write the following shell script:
If file $ your_file | grep text>/dev/null; then
Echo "This is a text file ."
Else
Echo "This is not a text file ."
Fi
Enjoy!