J2EE fragmentation notes

Source: Internet
Author: User

I 've been catching up for a while.CodeYou have no time to take notes. I haven't forgotten to record it all over the past two days. It's a bit fragmented. Remember what to write.

1. batch processing data of Java. SQL. preparedstatement.

Previously, it was all inserted one by one. I thought it was too 2. So I found that the preparedstatement can be processed in batches and directly pasted with the Demo code.

 
Preparedstatement PS = conn. preparestatement (
 
"Insert into employees values (?, ?, ?)");
 
 
For(N = 0; n <100; n ++ ){
 
 
 
PS. setstring (name [N]);
 
PS. setlong (ID [N]);
 
PS. setint (salary [N]);
PS. addbatch ();
 
}
 
Ps.exe cutebatch ();
 
 

If the data volume is too large, you can limit the batch size. For example, you can submit every 1000 records once.

 
Preparedstatement PS = conn. preparestatement (
"Insert into employees values (?, ?, ?)");
 
Int[] Result;
 
IntAffectedline = 0;
 
For(N = 0; n <2345; n ++ ){
PS. setstring (name [N]);
 
PS. setlong (ID [N]);
 
PS. setint (salary [N]);
 
PS. addbatch ();
 
If(I + 1) % batch_limite = 0 ){
Resulteffecpstmt.exe cutebatch ();
 
Affectedline + = calculatesum (result );
 
Conn. Commit ();
 
PS. clearbatch ();
 
}
Resultappsps.exe cutebatch ();
 
Affectedline + = calculatesum (result );
 
}

2. Obtain the current web root directory:

 
Public StaticString getwebclassespath ()ThrowsUrisyntaxexception {
String Path = globalparameter.Class. Getresource ("/"). Touri (). getpath ();
 
ReturnPath;
 
 
 
}
 
 
Public StaticString getwebinfpath ()ThrowsIllegalaccessexception, urisyntaxexception {
 
String Path = getwebclassespath ();
 
If(Path. indexof ("WEB-INF")> 0 ){
Path = path. substring (0, path. indexof ("WEB-INF") + 8 );
 
}Else{
 
Throw NewIllegalaccessexception ("Path retrieval Error");
 
}
ReturnPath;
 
}
 
 
 
Public StaticString getwebroot ()ThrowsIllegalaccessexception, urisyntaxexception {
String Path = getwebclassespath ();
 
If(Path. indexof ("WEB-INF")> 0 ){
 
Path = path. substring (0, path. indexof ("WEB-INF/classes"));
 
}Else{
Throw NewIllegalaccessexception ("Path retrieval Error");
 
}
 
ReturnPath;
 
}
 
 
@ Test
 
Public VoidTestpath ()ThrowsIllegalaccessexception, urisyntaxexception {
 
System. Out. println ("Web class Path ="+ Getwebclassespath ());
 
System. Out. println ("WEB-INF Path ="+ Getwebinfpath ());
System. Out. println ("Webroot path ="+ Getwebroot ());
 
}

In the development environment (I am eclipse J2EE + Tomcat 7), eclipse uses a server plug-in to simulate Tomcat services, therefore, the webroot path obtained through the above method is usually D: \ workspace \. metadata \. plugins \ Org. eclipse. WST. server. such as core \ tmp0 \ wtpwebapps \ mystruts \. If a dynamically generated file is to be placed in the web directory, find it here. It seems to be a temporary folder, which has not been carefully studied. (Files first placed under the project webroot will be copied to this temporary directory, so they can all be found)

3. Bidirectional map and bimap. Support key search through value

Google collection is used, which is described here.

Usage

Bimap <string, string> map = hashbimap. Create ();
 
Map. Put ("Kafka0102","1");
 
System. Out. println (Map. Get ("Kafka0102"));
System. Out. println (Map. Inverse (). Get ("1");// The output reverse data does not provide a separate function, but needs to call inverse (). Get ()

 

 

4. I think so much about it now. I will try again later.

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.