The spring Framework's jdbctemplate operations for the DAO layer include CRUD

Source: Internet
Author: User
Tags java web

Crud refers to the basic operations of a database or persistence layer, including

Add (Create), read query (Retrieve fetch), UPDATE, and delete

Spring not only encapsulates JDBC, it also encapsulates hibernate, and Ibatis

JdbcTemplate is similar to the Dbutils small frame feature in Java Web

Encapsulation simplifies code, requires JAR package support, JdbcTemplate also requires two jar packages:

Spring-jdbc-4.2.4.release.jar

Spring-tx-4.2.4.release.jar

Previously, there were 10 jar packages, implemented beans annotation AOP and other functions, copied below

Four core jar packages in spring compressed package required

Beans, context, core, and expression

Https://pan.baidu.com/s/1qXLHzAW

and log jar Packages

Commons-logging and log4j

https://pan.baidu.com/s/1mimTW5i

Add one more

Spring-aop-5.0.1.release.jar (for annotations, included in the Spring-framework library)

Further increase

Spring-aspects-5.0.1.release.jar (included in the Spring-framework library)

Aspectjweaver-1.8.12.jar (Official Http://mvnrepository.com/artifact/org.aspectj/aspectjweaver)

Aopalliance-1.0.jar (Official http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0)

Briefly review the operation of the original Java connection database

 PackageCom.swift;//The package imported here is java.sql.Connection instead of Com.mysql.jdbc.ConnectionImportjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement;Importjava.util.ArrayList;Importjava.util.List; Public classTESTJDBC { Public Static voidMain (string[] args) {Connection conn=NULL; Statement St=NULL; ResultSet RS=NULL; Try {            //1, Load driveClass.forName ("Com.mysql.jdbc.Driver"); } Catch(ClassNotFoundException e) {e.printstacktrace (); }        Try {            //2, link database, using Com.mysql.jdbc.Connection package will be errorList<user> list=NewArraylist<user>(); Conn=drivermanager.getconnection ("Jdbc:mysql://localhost:3306/sw_database?user=root&password=root"); //3. Create a connection statementst=conn.createstatement (); //4. Execute SQL statement to get result setRs=st.executequery ("SELECT * from Sw_user"); //5. Loop to get Database field generation Object             while(Rs.next ()) {intId=rs.getint ("id"); String username=rs.getstring ("username"); String Password=rs.getstring ("Password"); User User=NewUser (Id,username,password);            List.add (user); }            //6. Iterating through the list of objects             for(User user:list) {System.out.println (user.tostring ()); }                    } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }finally {            //7. Close result set            Try {                if(rs!=NULL) {rs.close (); }            } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }            //7. Close the connection statement            Try {                if(st!=NULL) {st.close (); }            } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }            //7. Close the database connection            Try {                if(conn!=NULL) {conn.close (); }            } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }        }    }    }

The spring Framework's jdbctemplate operations for the DAO layer include CRUD

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.