Some practical experience in developing servlet and shell scripts in Oracle Jserv

Source: Internet
Author: User

 

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.