SQL Server parses xml to Oracle and SQL Server Oracle

Source: Internet
Author: User

SQL Server parses xml to Oracle and SQL Server Oracle

Write a program: Read a table in SQLserver Based on the status bit and download the value of one of the fields. The value is of the XML type, insert the content of the XML file to another Oracle database, and update the table flag, indicating that this record has been updated.

My idea is to use java to write a webservice, and then use C # To write a windows service that runs every 30 minutes. I think it is more convenient to operate oracle in java. Using C # To write windows Services is because I only know that I can use C # To write windows Services, and the background silent operation is quite good.

The seemingly simple program finally took three days to realize the demand, because there were several minor problems that had not yet been solved.

Next, let's list the problems encountered.

Q1 Parse XML content using java

Resolved: Reference http://www.ibm.com/developerworks/cn/xml/dm-1208gub/index.html

The first DOM method is used.

 

Q2 java jdbc connection to the Oracle database

Solved: the key code is as follows:

String driverClassName = "oracle. jdbc. driver. OracleDriver ";

String url = "jdbc: oracle: thin: @ // 192.168.101.22: 1521/orcl ";

Note that the SQL statement in java code should not end with a semicolon; otherwise, the error java. SQL. SQLSyntaxErrorException: ORA-00911: invalid characters will be reported.

 

Q3 how to write a webservice in java

Resolved:

Reference: http://javapapers.com/web-service/java-web-service-using-eclipse/

After writing the java class (under the Dynamic Web Project), right-click to create a webservice.

Note that the method to be generated must start with a lower-case letter. Otherwise, it cannot be called. The method in java must start with lowercase!

I have written a Service class in java. Next

 

Q4 downloaded the XML file and encountered an exception when parsing the XML file:

1 byte of the UTF-8 sequence in xml is Invalid ([character encoding] Invalid byte 1 of 1-byte UTF-8 sequence

The cause of this problem is that the default encoding format for downloading XML files in java is GBK, and when we use DOM to parse xml files, we use UTF-8 to parse, the encoding is not correct, so the xml document cannot be recognized.

Http://bbs.itheima.com/thread-29901-1-1.html

I have never tried this method in http://blog.csdn.net/zhangzhikaixinya/article/details/7727938.

Code Implementation

1/** 2 * write log 3 * @ param logpath Log File Path 4 * @ param logtext log Content 5 */6 public void WriteLog (String logpath, String logtext) 7 {8 File file = new File (logpath); 9 10 try11 {12 // Writer out = new FileWriter (file, true ); 13 OutputStreamWriter out = new OutputStreamWriter (new FileOutputStream (file, true), "UTF-8"); 14 out. write (logtext); 15 out. close (); 16} catch (IOException e) 17 {18 // TODO Auto-generated catch block19 e. printStackTrace (); 20} 21}Write File specify UTF-8 Encoding

 

Q5 write the program, publish it locally, pass the test, publish it to the remote server, and the call prompt 404 cannot find the resource. I use java webservice called by C.

Unsolved ......

Run locally for the moment.

 

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.