How to import xml into a database by using JAVA
We know that there are many ways to import data into the database by inserting data into the database by importing xml into the database. In the past, the most commonly used method was to insert a piece of data through SQL statements, today, we will learn to add the data in xml to the database once:
First, write an xml file:
Then write the method to read the xml file: Introduce the dom4j jar package to lib under WEB-INFO and add references:
Imp
(NUMERO, REPOSICION, NOMBRE, TURNOS) values (?, ?, ?, ?) "; Connection conn = null; PreparedStatement pstmt = null; try {conn = DbUtil. getConnection (); pstmt = conn. prepareStatement (SQL); // locate the location of the XML file to be read, Document doc = new SAXReader (). read (new File ("D:/share/JavaProjects/drp/test_xmlImport/xml/test01.XML"); // extract the content List itemList = doc of the specified node in the XML File. selectNodes ("/ACCES
When encapsulation, we often need to use XML to define some specifications, while running the read alone is certainly not a problem, but these XML is often put in the jar bag, so that these things can not find out. The XML definitions used in this article are as follows:
Copy Code code as follows:
Here's a look at the code:
Copy Code code as follows:
public void read () {
try {
nbs p; Document doc = new Saxreader (). Read (New File ("Src/user.xml");
We know there are many ways to Import XML into a database by inserting the number into the database.,most of the previous contacts were throughSQLthe statement simply inserts a single piece of data,to learn today is toXMLdata is added to the database at once:the first thing to write is an XML file : and then write the ReadXMLmethod of the file:putdom4jof theJarpackage introduced toWeb-infounder theLiband add a reference:Import org.dom4j.document;import org.dom4j.element;import org.dom
result is correct:
NUMERO =00045050 NUMERO =00045051 NUMERO =00045050NUMERO =00045051
When I first came into contact with dom4j, I felt this thing was mysterious, because although I knew about XML files before, I never used it. I always felt that XML is definitely not easy to operate. When I learned that dom4j can easily read XML files, how simple is it to read
class that can throw a non-inspected exception, called a task, implement the Runnable interface, implement the Run () method, and deliberately encode a section of code that produces a non-inspected exception, such as converting a string to a number. The code is as follows:
Copy Code code as follows:
public class Task implements Runnable {
@Override
public void Run () {
int numero = integer.parseint ("diguage.com");
}
}
Application 1:-------1. Import the jar packages of dom4j and jaxen2. Reading is easier than pure dom4j:Document Doc = new saxreader (). Read (new file ("D:/share/javaprojects/DRP/test_xmlimport/XML/test01.xml "));List itemlist = Doc. selectnodes ("/ACCESOS/item/socio"); // dom4j + xpathFor (iterator iter = itemlist. iterator (); ITER. hasnext ();){Element El = (element) ITER. Next ();String numero = El. elementtext ("
can read the content in the XML file. Let's see if the result is correct:
NUMERO =00045050NUMERO =00045051
Perfect! The result is correct. So far, we have used only a few lines of code, and the data in XML has been encapsulated into the object. There is almost no difference between retrieving the data in XML and retrieving the data in the array, this is the power of dom4j. With dom4j, when I tried to operate XML files again, I was so impatient that
Dynamically generated controls, it should be written like this: with do begin Parent:=panelcheque; Name:='Bank'+curnumber; Left:=+; Top:=curtop; Height:=; Width:=n; Text:='; End;But accidentally wrote: with do begin Parent:=panelcheque; Name:='numero'+curnumber; Left:=; Top:=curtop; Height:=; Width:=; Text:='; End;Result error: A
) Implementation of/etc/rc.d/rc.localRedhat run mode 2,3,5 the/etc/rc.d/rc.local as the last file in the Init script, so users can add in this file their own commands that need to be executed before landing after other initialization work6) Execute/bin/loginThe login program will prompt the user to enter the account number and password, and then code and confirm the correctness of the password, if the two are consistent, users to initialize the environment, and give control to the shell, that is
plus Numero US Extensions
* Transactional configuration database with C and Python bindings
* high-performance Forwarding Usin G A Linux kernel moduleThis introduction, may have seen no concept, and then from the virtual computing environment of the network structure from the beginning of the introduction. This is useful for understanding open vswitch.
Before the computing virtualization technology is popularized, the NIC is the exit of host
: Cyrillic capital letter YiB0 = u + 00b0: Degree signB1 = u + 00b1: plus-minus signB2 = u + 0406: Cyrillic capital letter BYELORUSSIAN-UKRAINIAN IB3 = u + 0456: Cyrillic small letter BYELORUSSIAN-UKRAINIAN IB4 = u + 0491: Cyrillic small letter ghe with upturnB5 = u + 00b5: Micro signB6 = u + 00b6: pilcrow signB7 = u + 00b7: middle dotB8 = u + 0451: Cyrillic small letter IoB9 = u + 2116: numero signBA = u + 0454: Cyrillic small letter Ukrainian IEBB =
This article is a summary of the study of the article on the network, thank you for your selfless sharing.1 , Java in a 2 type of exception:Check for exceptions: These exceptions must be forced to capture them or in a method throws clause. No exception checked: These exceptions do not have to be forced to capture them.2 , in a thread object's Run () method throws a check exception, we must capture and process them. Because the run() method does not accept the throws clause. When a non-check exce
subtle white ghost buttons; second, it creates a relaxed atmosphere; Finally, it embodies the brand identity.
Invelab
Similarly, the designer tries to create a perfect contrast between the background and the foreground, while also directing attention to the picture in the studio. Bright Purple is effectively complementary to white.
M2b
The cheerful translucent gradient reinforces the visual performance of the site. As a result of this approach, the new colors make the image behind
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.