(busno, startTime, endTime );}
} 4 Write dao layer interface
[Java]/*** Super capacitor data analysis Dao* @ Author hanshibo**/Public interface BusSuperCapityAnalyDao {Public List }
/*** Super capacitor data analysis Dao* @ Author hanshibo**/Public interface BusSuperCapityAnalyDao {
Public List } 5 Write the dao layer implementation. Use the query method of spring jdbcTemplate, and use a placeholder (?) Qu
Tags: java development Spring jdbctemplate jdbc TemplateSpring's jdbctemplate is a template encapsulation of JDBC, which provides a set of JDBC templates that allow us to write persistent layer code to reduce redundant code, simplify the JDBC code, and make the code look more concise. Before we introduce spring's jdbctemplate
Tags: spring-using configuration files to complete JdbcTemplate operations databaseFirst, create a spring projectProject Name: spring101302Ii. adding a jar package to the project1. Create a Lib directory in your project/lib2. Add spring support under the Lib directoryCommons-logging.jarJunit-4.10.jarLog4j.jarMysql-conn
/sw_database "); //datasource.setuser ("root");//Datasource.setpassword ("root");
String SQL= "INSERT into Sw_user (Username,password) VALUES (?,?)"; intCount=jdbctemplate.update (SQL, "Bullet", "battle-Man song"); if(count==1) {
return true; }
return false; }
} To use the JdbcTemplate object in Userdao, this object is also injected through the config file XML, which needs to be setjdbctemplate () to match The
The Spring framework performs crud operations on the jdbcTemplate of the dao layer, namely, update operations on the database and jdbctemplatecrud operations.
Use jdbcTemplate
The principle is to load the Driver Class. forName ("com. mysql. jdbc. Driver ");
And Connection conn = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/sw_database? User = ro
classes//Note that the call is not a queryForList methodPublicvoidTestqueryforlist () {String sql= "select Id,last_name,email from tables where id>?"; RowmapperNew BeanpropertyrowmapperClass); List); SYSTEM.OUT.PRINTLN (employees); }/*** Get a record from the database, actually get a corresponding object * Note that it is not called queryforobject (String sql, class*/PublicvoidTestqueryforobject () {String sql= "select Id,last_name lastname,email,dept_id as \" department.id\ "from tables where
Summary:Put the spring jar package into the Lib directory, the Jar can be based on the function you want to choose, if lazy or do not want to use the function later put together, pay attention to not put the document jar and source jarSuddenly think of spring's requirements for the environment, also forget to say that my JDK version is 1.6, the database will use MySQL, Application server is Tomcat7.0First go to sp
Write in front
Spring has always been shanfanjiujian, so we have designed a very popular bean management model that simplifies the management of beans in development and writes a lot less repetitive code. JdbcTemplate's design is more impressive, lightweight, and can be used as an ORM as well as a JDBC-like flexibility. And in JdbcTemplate a class, contains two kinds of design patterns, read after the
Tags: rgb font call PES @param color CLI nal SpringNote: This article is from the spring jdbctemplate call stored procedure, return list ObjectSpring JdbcTemplate calls the stored procedure and returns the List object method:/** * Call stored procedure * @param spname */@SuppressWarnings ("unchecked") PublicList//procedure = "{call Wcity2_statistic.sp_uservisit_
Tags: prepare ges crud Create ring Spring COM Add styleFirst, JdbcTemplate preparation1. Import the jar package associated with the JdbcTemplate2. Setting Up Database Information3. Create a JdbcTemplate object, set the data sourceSecond, add the operation1. Code2. ResultsThird, modify the operation1. Code2. ResultsIv. Delete operation1. Code2. ResultsFive, query
Label:Currently I am exposed to the spring database operations mainly include two kinds, mainly use JdbcTemplate and hibernatetemplate. The latter is used in conjunction with hibernate operations. Both provide persistent layer access templating, and only need to obtain a sessionfactory to perform persistence operations. Can complete the increase and deletion check operation. There are two ways to get
/schema/context/spring-context.xsd " >Iv. Testing1. Create the test directory on the project/test2. Creating a test package under the test directoryPackage Name: Cn.jbit.spring101301.test3. Create a test class under a test packageTest class Name: Jdbctemplatedemo.javaTest the contents of the class:public class Jdbctemplatedemo {/*** Add data using spring JdbcTemplate
() + "," +book.getbooktype ());}}}Careful you, you will find a series of methods in JdbcTemplate examples, such as: Queryforxxx,update,delete greatly simplifies the JDBC operation.Of course, it can be further optimized, that is, through dependency injection, directly inject jdbctemplate into the DAO class's JDBCT field.First look at the new applicationcontext.xml configuration file:Xmlns:xsi= "Http://www.w
and consume resources
//Note the order of closing, the last used first close
if(Result! =NULL) Result.close ();if(Pre! =NULL) Pre.close ();if(Con! =NULL) Con.close (); System.out.println ("The database connection is closed! "); }Catch(Exception e)
{E.printstacktrace (); }
}
}/** * Test SQL injection attacks.
JdbcTemplate This security issue does not exist. * @param ID * @return * *
Pub
Original address http://alex007.iteye.com/blog/869544
Spring simplejdbctemplate encapsulates the call of the stored procedure, but unfortunately it can only be used in the jdk1.5 environment and cannot be used in the jdk1.4 environment. jdbctemplate is fully applicable to the jdk1.4 environment, the following describes how to use jdbctemplate to call an oracle st
Jdbctemplate was used in the project at the beginning. To improve the development efficiency, Hibernate was used. However, it was found that hibernate was not very efficient during batch operations. So now we use jdbctemplate and Hibernate to mix, jdbctemplate and hibernate can be mixed, there are several considerations.
1. If the
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.