Label:Original address: http://blog.csdn.net/will_awoke/article/details/12617383 has been using ORM, today with JdbcTemplate again depressed once again. First look at this method: At first glance, I want to pass a generic T (the actual code execution, this T can be my custom bean), and then I can return a list Thus, the following code appears: [Java]View Plaincopy
listClass);
One execution, found out the exception: ERROR [Com.ruhuiyu
= This. Nativejdbcextractor.getnativepreparedstatement (PS); - }
-T result =action.doinpreparedstatement (pstouse); - Handlewarnings (PS); - returnresult; - }
in Catch(SQLException ex) { - //Release Connection Early, to avoid potential Connection pool deadlock to //In the case when the exception translator hasn ' t been initialized yet.
+ if(PSCinstanceofParameterdisposer) {
- ((Parameterdisposer) PSC). Cleanupparam
= new temp ();Temp.settempid (TID);Temp.settempname (Tname);Temps.add (temp);}return temps;}});return temps;}}Vi. Configuring DAO in the core configuration fileSeven, testing1. Create the test directory on the project/test2. Creating a test package under the test directoryPackage Name: Cn.jbit.spring101301.dao3. Create a test class under a test packageTest class Name: Jdbctemplatedemo.javaTest the contents of the class:public class Jdbctemplatedemo {/*** Use
= new temp ();Temp.settempid (TID);Temp.settempname (Tname);Temps.add (temp);}return temps;}});return temps;}}Vi. Configuring DAO in the core configuration fileSeven, testing1. Create the test directory on the project/test2. Creating a test package under the test directoryPackage Name: Cn.jbit.spring101301.dao3. Create a test class under a test packageTest class Name: Jdbctemplatedemo.javaTest the contents of the class:public class Jdbctemplatedemo {/*** Use
Tags: springIntermediate Library mode synchronizing DataConfigure a JdbcTemplate bean in the Spring IoC container, inject the DataSource into it, and then inject jdbctemplate into the custom DAO. Requirements: Write archives, Department base data to Intermediate library, take archives as an example
TriggerView all trigger, view trigger Create statement
Application:Use spring's jdbctemplate to query the database, get a list of lists of results, database table fields and entity classes automatically correspond, you can use beanpropertyrowmapper.Note:Automatic binding requires the same column name as the Java entity class name, such as: The property name "UserName" can match the column field "UserName" or "user_name" in the database. In this way, we do not need a manual binding, greatly improving the d
Today I'm going to show you about JdbcTemplate implementing queries and additions to the databaseThe first is to addFirst step, everybody knows. Create an entity classThen write a method to pass the entity class as a parameter.In implementing this interfaceJdbcdaosupport This must be a jar package for spring to inherit it to interact with the databaseThe service layer and DAO write a similar interface to th
In spring JDBC Development, you can use the JdbcTemplate and Jdbcdaosupport classes to simplify the operation of the entire database. In this tutorial, we will repeat the previous article Spring+jdbc example, looking at a different example between previous (no JdbcTemplate support) and later (with support for
Application:Use spring's jdbctemplate to query the database, get a list of lists of results, database table fields and entity classes automatically correspond, you can use beanpropertyrowmapper.Note: The Beanpropertyrowmapper implements the RowMapper interface.Attention:Automatic binding requires the same column name as the Java entity class name, such as: The property name "UserName" can match the column field "UserName" or "user_name" in the databas
Here's a step-by-step procedure for implementing a custom paging using the spring JdbcTemplate method:
Step one to create the Splitpageresultsetextractor class:
Package com.utils;
Import Java.sql.ResultSet;Import java.sql.SQLException;Import java.util.ArrayList;Import java.util.List;
Import org.springframework.dao.DataAccessException;Import Org.springframework.jdbc.core.ResultSetExtractor;Import Org.springf
Tags: des blog http os java using IO for fileDescription: The current scenario is to deploy and configure Master-slave (Master-slave) relationships in two different servers in a database (MYSQL) replication (binlog) manner;and requires a program of data manipulation methods to access different databases, such as the update method to access the primary database server, the query method access from the database server.That is, "adding and deleting" and "check" separate access to two servers, of co
Software 152 class Yang JinhongSpring uses JdbcTemplate, Jdbcdaosupport, and namedparameterjdbctemplate to manipulate databases, but JdbcTemplate is most commonly used and easiest to use.Jdbc.properties:user=rootpassword=123driverclass=com.mysql.jdbc.driverjdbcurl=jdbc\:mysql\:///spring? Encoding\=uft-8initpoolsize=5maxpoolsize=20 Applicationcontext.xml Impor
The Project introduces a helper class (JDBC Template) for JDBC in spring that encapsulates the operation of JDBC and uses it to build a project project structure to create a MAVEN project, as shown in the figure above Maven dependency jar Rollup
New test class, creating data table
Package com.curd.spring.test;
Import Org.junit.Test;
Import org.springframework.jdbc.core.JdbcTemplate;
Import Org.springframework.jdbc.datasource.DriverManagerDa
1. Querying a row of data and returning an int type resultjdbcTemplate.queryForInt("select count(*) from test"); 2. Query a row of data and convert the row data to a map returnjdbcTemplate.queryForMap("select * from test where name=‘name5‘"); 3. Query a row for any type of data, and the last parameter specifies the type of return resultjdbcTemplate.queryForObject("select count(*) from test", Integer.class); 4. Query a batch of data, by default convert each row of data to mapjdbcTemplate.query
1. Querying object Public Classify Queryclassifbyid (int ID) { String sql= "SELECT * from T_classify where id=?" ; New object[] {ID}; = Jdbctemplate.queryforobject (sql, args, parameterizedbeanpropertyrowmapper.newinstance (classify. Class)); return classify; }2. Query List Public List Getallmenu () { String sql= "SELECT * from t_classify"; List Class)); return list; }3. Number of query records Public int GetCount () {
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.