- 浏览: 840437 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
renzhengzhi:
请教一下楼主,公有云和私有云的开发,具体要做哪些工作呢?我拿到 ...
4,云的4 种模式 -
SangBillLee:
我用了solr5.5,用SolrQuery查询,没法高亮,不知 ...
solr5.x快速入门 -
lw900925:
这翻译读起来真是别扭。
solr in action翻译-第一章1.1 -
springjpa_springmvc:
spring mvc demo教程源代码下载,地址:http: ...
Spring MVC性能提升 -
h416373073:
正遇到了此问题不知如何解决, 多谢分享
solr错误
jdbcTemplate整理
为了实现基本的CRUD操作,spring给我们提供了jdbcTemplate这个模板类.实现最常用的CRUD操作。
先看jdbcTemplate的定义
public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { /** Custom NativeJdbcExtractor */ private NativeJdbcExtractor nativeJdbcExtractor; /** If this variable is false, we will throw exceptions on SQL warnings */ private boolean ignoreWarnings = true; /** * If this variable is set to a non-zero value, it will be used for setting the * fetchSize property on statements used for query processing. */ private int fetchSize = 0; /** * If this variable is set to a non-zero value, it will be used for setting the * maxRows property on statements used for query processing. */ private int maxRows = 0; /** * If this variable is set to true then all results checking will be bypassed for any * callable statement processing. This can be used to avoid a bug in some older Oracle * JDBC drivers like 10.1.0.2. */ private boolean skipResultsProcessing = false; }
JdbcTemplate继承自JdbcAccessor,同时实现了JdbcOperations接口,在整个框架中这个JdbcOperations接口只让
JdbcTemplate实现了。JdbcOperations定义了CRUD的操作。
public interface JdbcOperations { //------------------------------------------------------------------------- // Methods dealing with a plain java.sql.Connection //------------------------------------------------------------------------- /** * Execute a JDBC data access operation, implemented as callback action * working on a JDBC Connection. This allows for implementing arbitrary * data access operations, within Spring's managed JDBC environment: * that is, participating in Spring-managed transactions and converting * JDBC SQLExceptions into Spring's DataAccessException hierarchy. * <p>The callback action can return a result object, for example a * domain object or a collection of domain objects. * @param action the callback object that specifies the action * @return a result object returned by the action, or <code>null</code> * @throws DataAccessException if there is any problem */ Object execute(ConnectionCallback action) throws DataAccessException; //------------------------------------------------------------------------- // Methods dealing with static SQL (java.sql.Statement) //------------------------------------------------------------------------- /** * Execute a JDBC data access operation, implemented as callback action * working on a JDBC Statement. This allows for implementing arbitrary data * access operations on a single Statement, within Spring's managed JDBC * environment: that is, participating in Spring-managed transactions and * converting JDBC SQLExceptions into Spring's DataAccessException hierarchy. * <p>The callback action can return a result object, for example a * domain object or a collection of domain objects. * @param action callback object that specifies the action * @return a result object returned by the action, or <code>null</code> * @throws DataAccessException if there is any problem */ Object execute(StatementCallback action) throws DataAccessException; /** * Issue a single SQL execute, typically a DDL statement. * @param sql static SQL to execute * @throws DataAccessException if there is any problem */ void execute(String sql) throws DataAccessException; /** * Execute a query given static SQL, reading the ResultSet with a * ResultSetExtractor. * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * execute a static query with a PreparedStatement, use the overloaded * <code>query</code> method with <code>null</code> as argument array. * @param sql SQL query to execute * @param rse object that will extract all rows of results * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if there is any problem executing the query * @see #query(String, Object[], ResultSetExtractor) */ Object query(String sql, ResultSetExtractor rse) throws DataAccessException; /** * Execute a query given static SQL, reading the ResultSet on a per-row * basis with a RowCallbackHandler. * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * execute a static query with a PreparedStatement, use the overloaded * <code>query</code> method with <code>null</code> as argument array. * @param sql SQL query to execute * @param rch object that will extract results, one row at a time * @throws DataAccessException if there is any problem executing the query * @see #query(String, Object[], RowCallbackHandler) */ void query(String sql, RowCallbackHandler rch) throws DataAccessException; /** * Execute a query given static SQL, mapping each row to a Java object * via a RowMapper. * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * execute a static query with a PreparedStatement, use the overloaded * <code>query</code> method with <code>null</code> as argument array. * @param sql SQL query to execute * @param rowMapper object that will map one object per row * @return the result List, containing mapped objects * @throws DataAccessException if there is any problem executing the query * @see #query(String, Object[], RowMapper) */ List query(String sql, RowMapper rowMapper) throws DataAccessException; /** * Execute a query given static SQL, mapping a single result row to a Java * object via a RowMapper. * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * execute a static query with a PreparedStatement, use the overloaded * <code>queryForObject</code> method with <code>null</code> as argument array. * @param sql SQL query to execute * @param rowMapper object that will map one object per row * @return the single mapped object * @throws IncorrectResultSizeDataAccessException if the query does not * return exactly one row * @throws DataAccessException if there is any problem executing the query * @see #queryForObject(String, Object[], RowMapper) */ Object queryForObject(String sql, RowMapper rowMapper) throws DataAccessException; /** * Execute a query for a result object, given static SQL. * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * execute a static query with a PreparedStatement, use the overloaded * <code>queryForObject</code> method with <code>null</code> as argument array. * <p>This method is useful for running static SQL with a known outcome. * The query is expected to be a single row/single column query; the returned * result will be directly mapped to the corresponding object type. * @param sql SQL query to execute * @param requiredType the type that the result object is expected to match * @return the result object of the required type, or <code>null</code> in case of SQL NULL * @throws IncorrectResultSizeDataAccessException if the query does not return * exactly one row, or does not return exactly one column in that row * @throws DataAccessException if there is any problem executing the query * @see #queryForObject(String, Object[], Class) */ Object queryForObject(String sql, Class requiredType) throws DataAccessException; /** * Execute a query for a result Map, given static SQL. * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * execute a static query with a PreparedStatement, use the overloaded * <code>queryForMap</code> method with <code>null</code> as argument array. * <p>The query is expected to be a single row query; the result row will be * mapped to a Map (one entry for each column, using the column name as the key). * @param sql SQL query to execute * @return the result Map (one entry for each column, using the * column name as the key) * @throws IncorrectResultSizeDataAccessException if the query does not * return exactly one row * @throws DataAccessException if there is any problem executing the query * @see #queryForMap(String, Object[]) * @see ColumnMapRowMapper */ Map queryForMap(String sql) throws DataAccessException; }
中间的省略了。
定义的都是jdbc几方法。
JdbcAccessor是一个抽象类,本身继承了InitializingBean接口,在InitializingBean接口中只定义了一个方法
public interface InitializingBean { /** * Invoked by a BeanFactory after it has set all bean properties supplied * (and satisfied BeanFactoryAware and ApplicationContextAware). * <p>This method allows the bean instance to perform initialization only * possible when all bean properties have been set and to throw an * exception in the event of misconfiguration. * @throws Exception in the event of misconfiguration (such * as failure to set an essential property) or if initialization fails. */ void afterPropertiesSet() throws Exception; }
关于InitializingBean 这个接口以后介绍。继续返回到JdbcAccessor这个抽象类中,这个类做了什么呢?按照源代码
的注解说这个类是JdbcTemplate的一个基本类,同时也是其他Jdbc操作类的一个DAO工具类。定义了通用的属性,比如
DataSource和异常等信息。
看源代码
public abstract class JdbcAccessor implements InitializingBean { protected final Log logger = LogFactory.getLog(getClass()); /** Used to obtain connections throughout the lifecycle of this object */ private DataSource dataSource; /** Helper to translate SQL exceptions to DataAccessExceptions */ private SQLExceptionTranslator exceptionTranslator; private boolean lazyInit = true; /** * Set the JDBC DataSource to obtain connections from. */ public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } /** * Return the DataSource used by this template. */ public DataSource getDataSource() { return dataSource; } /** * Specify the database product name for the DataSource that this accessor uses. * This allows to initialize a SQLErrorCodeSQLExceptionTranslator without * obtaining a Connection from the DataSource to get the metadata. * @param dbName the database product name that identifies the error codes entry * @see SQLErrorCodeSQLExceptionTranslator#setDatabaseProductName * @see java.sql.DatabaseMetaData#getDatabaseProductName() */ public void setDatabaseProductName(String dbName) { this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dbName); } /** * Set the exception translator for this instance. * <p>If no custom translator is provided, a default SQLErrorCodeSQLExceptionTranslator * is used which examines the SQLException's vendor-specific error code. * @param exceptionTranslator exception translator * @see org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator * @see org.springframework.jdbc.support.SQLStateSQLExceptionTranslator */ public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator) { this.exceptionTranslator = exceptionTranslator; } /** * Return the exception translator for this instance. * <p>Creates a default SQLErrorCodeSQLExceptionTranslator for the specified * DataSource if none set. */ public SQLExceptionTranslator getExceptionTranslator() { if (this.exceptionTranslator == null) { DataSource dataSource = getDataSource(); if (dataSource != null) { this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator (dataSource); } else { this.exceptionTranslator = new SQLStateSQLExceptionTranslator(); } } return this.exceptionTranslator; } /** * Set whether to lazily initialize the SQLExceptionTranslator for this accessor, * on first encounter of a SQLException. Default is "true"; can be switched to * "false" for initialization on startup. * <p>Early initialization only applies if <code>afterPropertiesSet</code> is called. * @see #getExceptionTranslator * @see #afterPropertiesSet */ public void setLazyInit(boolean lazyInit) { this.lazyInit = lazyInit; } /** * Return whether to lazily initialize the SQLExceptionTranslator for this accessor. */ public boolean isLazyInit() { return lazyInit; } /** * Eagerly initialize the exception translator, * creating a default one for the specified DataSource if none set. */ public void afterPropertiesSet() { if (getDataSource() == null) { throw new IllegalArgumentException("dataSource is required"); } if (!isLazyInit()) { getExceptionTranslator(); } } }
这里只定义了三个属性, DataSource dataSource;SQLExceptionTranslator exceptionTranslator;boolean
lazyInit = true;DataSource 不用再说了,已经介绍过了,下面说说这个SQLExceptionTranslator,这到底是什么,
做什么用的,其实从名字就不能猜测出来,是一个sql异常翻译者。就是把sql底层的异常翻译成spring的异常
public interface SQLExceptionTranslator { /** * Translate the given {@link SQLException} into a generic {@link DataAccessException}. * @param task readable text describing the task being attempted * @param sql SQL query or update that caused the problem. May be <code>null</code>. * @param ex the offending <code>SQLException</code> * @return the DataAccessException to throw */ DataAccessException translate(String task, String sql, SQLException ex); }
定义的一个接口,里面只有一个方法translate,意思是翻译的意思,
将一个sql异常转化为DataAccessException异常。
这个异常接口SQLExceptionTranslator 有俩个实现类,SQLErrorCodeSQLExceptionTranslator,
SQLStateSQLExceptionTranslator
SQLErrorCodeSQLExceptionTranslator的核心方法:
public class SQLErrorCodeSQLExceptionTranslator implements SQLExceptionTranslator { public DataAccessException translate(String task, String sql, SQLException sqlEx) { if (task == null) { task = ""; } if (sql == null) { sql = ""; } // First, try custom translation from overridden method. DataAccessException dex = customTranslate(task, sql, sqlEx); if (dex != null) { return dex; } // Check SQLErrorCodes with corresponding error code, if available. if (this.sqlErrorCodes != null) { String errorCode = null; if (this.sqlErrorCodes.isUseSqlStateForTranslation()) { errorCode = sqlEx.getSQLState(); } else { errorCode = Integer.toString(sqlEx.getErrorCode()); } if (errorCode != null) { // Look for defined custom translations first. CustomSQLErrorCodesTranslation[] customTranslations = this.sqlErrorCodes.getCustomTranslations(); if (customTranslations != null) { for (int i = 0; i < customTranslations.length; i++) { CustomSQLErrorCodesTranslation customTranslation = customTranslations[i]; if (Arrays.binarySearch (customTranslation.getErrorCodes(), errorCode) >= 0) { if (customTranslation.getExceptionClass() != null) { DataAccessException customException = createCustomException( task, sql, sqlEx, customTranslation.getExceptionClass()); if (customException != null) { logTranslation(task, sql, sqlEx, true); return customException; } } } } } // Next, look for grouped error codes. if (Arrays.binarySearch(this.sqlErrorCodes.getBadSqlGrammarCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new BadSqlGrammarException(task, sql, sqlEx); } else if (Arrays.binarySearch (this.sqlErrorCodes.getInvalidResultSetAccessCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new InvalidResultSetAccessException(task, sql, sqlEx); } else if (Arrays.binarySearch (this.sqlErrorCodes.getDataAccessResourceFailureCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new DataAccessResourceFailureException(buildMessage (task, sql, sqlEx), sqlEx); } else if (Arrays.binarySearch (this.sqlErrorCodes.getPermissionDeniedCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new PermissionDeniedDataAccessException(buildMessage (task, sql, sqlEx), sqlEx); } else if (Arrays.binarySearch (this.sqlErrorCodes.getDataIntegrityViolationCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx); } else if (Arrays.binarySearch (this.sqlErrorCodes.getCannotAcquireLockCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new CannotAcquireLockException(buildMessage(task, sql, sqlEx), sqlEx); } else if (Arrays.binarySearch(this.sqlErrorCodes.getDeadlockLoserCodes (), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new DeadlockLoserDataAccessException(buildMessage(task, sql, sqlEx), sqlEx); } else if (Arrays.binarySearch (this.sqlErrorCodes.getCannotSerializeTransactionCodes(), errorCode) >= 0) { logTranslation(task, sql, sqlEx, false); return new CannotSerializeTransactionException(buildMessage (task, sql, sqlEx), sqlEx); } } } // We couldn't identify it more precisely - let's hand it over to the SQLState fallback translator. if (logger.isDebugEnabled()) { String codes = null; if (this.sqlErrorCodes.isUseSqlStateForTranslation()) { codes = "SQL state '" + sqlEx.getSQLState() + "', error code '" + sqlEx.getErrorCode(); } else { codes = "Error code '" + sqlEx.getErrorCode() + "'"; } logger.debug("Unable to translate SQLException with " + codes + ", will now try the fallback translator"); } return this.fallbackTranslator.translate(task, sql, sqlEx); } }
根据 errorCode = sqlEx.getSQLState(),返回不同的值,返回不同的异常信息。
public class SQLStateSQLExceptionTranslator implements SQLExceptionTranslator { /** * Set of well-known String 2-digit codes that indicate bad SQL */ private static final Set BAD_SQL_CODES = new HashSet(6); /** * Set of well-known String 2-digit codes that indicate RDBMS integrity violation */ private static final Set INTEGRITY_VIOLATION_CODES = new HashSet(4); /** * Set of String 2-digit codes that indicate communication errors */ private static final Set RESOURCE_FAILURE_CODES = new HashSet(3); /** * Set of String 2-digit codes that indicate concurrency errors */ private static final Set CONCURRENCY_CODES = new HashSet(1); // Populate reference data. static { BAD_SQL_CODES.add("07"); BAD_SQL_CODES.add("37"); BAD_SQL_CODES.add("42"); BAD_SQL_CODES.add("2A"); BAD_SQL_CODES.add("65"); // Oracle throws this on unknown identifier BAD_SQL_CODES.add("S0"); // MySQL uses this - from ODBC error codes? INTEGRITY_VIOLATION_CODES.add("22"); // Integrity constraint violation INTEGRITY_VIOLATION_CODES.add("23"); // Integrity constraint violation INTEGRITY_VIOLATION_CODES.add("27"); // Triggered data change violation INTEGRITY_VIOLATION_CODES.add("44"); // With check violation CONCURRENCY_CODES.add("40"); // Transaction rollback RESOURCE_FAILURE_CODES.add("08"); // Connection exception RESOURCE_FAILURE_CODES.add("53"); // PostgreSQL uses this - insufficient resources (e.g. disk full) RESOURCE_FAILURE_CODES.add("54"); // PostgreSQL uses this - program limit exceeded (e.g. statement too complex) } /** Logger available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); public DataAccessException translate(String task, String sql, SQLException ex) { Assert.notNull(ex, "Cannot translate a null SQLException."); if (task == null) { task = ""; } if (sql == null) { sql = ""; } String sqlState = getSqlState(ex); if (sqlState != null && sqlState.length() >= 2) { String classCode = sqlState.substring(0, 2); if (BAD_SQL_CODES.contains(classCode)) { return new BadSqlGrammarException(task, sql, ex); } else if (INTEGRITY_VIOLATION_CODES.contains(classCode)) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } else if (RESOURCE_FAILURE_CODES.contains(classCode)) { return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); } else if (CONCURRENCY_CODES.contains(classCode)) { return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); } } // We couldn't identify it more precisely. return new UncategorizedSQLException(task, sql, ex); } /** * Build a message <code>String</code> for the given {@link SQLException}. * <p>Called when creating an instance of a generic * {@link DataAccessException} class. * @param task readable text describing the task being attempted * @param sql the SQL statement that caused the problem. May be <code>null</code>. * @param ex the offending <code>SQLException</code> * @return the message <code>String</code> to use */ protected String buildMessage(String task, String sql, SQLException ex) { return task + "; SQL [" + sql + "]; " + ex.getMessage(); } /** * Gets the SQL state code from the supplied {@link SQLException exception}. * <p>Some JDBC drivers nest the actual exception from a batched update, so we * might need to dig down into the nested exception. * @param ex the exception from which the {@link SQLException#getSQLState() SQL state} is to be extracted * @return the SQL state code */ private String getSqlState(SQLException ex) { String sqlState = ex.getSQLState(); if (sqlState == null) { SQLException nestedEx = ex.getNextException(); if (nestedEx != null) { sqlState = nestedEx.getSQLState(); } } return sqlState; } }
关于异常这部分以后详细介绍,在JdbcTemplate中碰到就稍微说说,以后再详细介绍,下面在返回来看JdbcTemplate.
这个类。
发表评论
-
Spring的PropertyPlaceholderConfigurer应用
2014-01-02 14:43 8341. PropertyPlaceholderConfigur ... -
spring 发送MAILJavaMailSenderImpl
2014-01-02 14:32 893spring对mail的支持是org.springframe ... -
spring REST中的内容协商ContentNegotiatingViewResolver
2014-01-02 14:23 1690一.REST内容协商介绍 RESTfu ... -
Spring MVC异常处理
2014-01-02 14:13 474Spring3.0中对异常的处理方法一共提供了两种:一种是使 ... -
Spring AOP 的@Aspect (转)
2013-12-19 10:04 5695转自:http://blog.csdn.net/tangh ... -
spring @component的作用
2013-12-19 09:54 9971、@controller 控制器(注入服务) 2、@se ... -
Spring MVC性能提升
2013-12-18 18:06 7132这几天在做公司内部SpringMVC的培训,培训之余看了看大 ... -
Spring MVC简介
2013-08-27 20:09 983Spring MVC简介 1.Sp ... -
SpringMVC中HandlerInterceptorAdapter的使用
2013-08-27 20:04 1994一般情况下,对来自浏览器的请求的拦截,是利用Filte ... -
Spring注解_详解
2013-08-27 20:01 930spring注解 @Autowired 注释 将 ... -
SpringMVC方法返回值的学习(注解版)
2013-08-22 09:38 1433/** * 项目名称:Spring3mvc de ... -
spring中的Log4jConfigListener作用
2013-08-21 10:40 1377使用spring中的Log4jConfigListener ... -
srping 异常
2010-11-15 14:32 1224Spring数据访问的根异常是DataAccessExcep ... -
使用spring的jdbcTemplate-----将JDBC操作建模为细粒度的对象
2010-09-11 16:32 15181,更新操作对象 首先考虑如何将User插入操作建模为一个操 ... -
使用spring的jdbcTemplate-----使用具名参数
2010-09-11 15:01 3602在JDBC用法中,SQL参数是用占位符?表示,并且受到位置的限 ... -
使用spring的jdbcTemplate-----SimpleJdbcTemplate的使用
2010-09-11 12:39 59081,用简单的JDBC模板更新数据库 传统的Jdb ... -
使用spring的jdbcTemplate-----简化JdbcTemplate模板的创建
2010-09-10 20:41 2288每次使用的时候,都要创建一个JdbcTemplate新实例,这 ... -
使用spring的jdbcTemplate-----用JDBC模板查询数据库
2010-09-10 00:26 11781JdbcTemplate类声明了几个重载的query()模板方 ... -
使用spring的jdbcTemplate-----用jdbc模板跟新数据库
2010-09-09 23:21 44991,用语句创建器更新数据库第一个回调接口是PreparedSt ... -
spring中jdbcTemplate归纳2
2010-09-07 22:01 2162用语句创建器更新数据库第一个回调接口是PerparedStat ...
相关推荐
在这个实例工程中,我们将深入探讨Spring JdbcTemplate的基本使用、优势以及常见操作。 一、Spring JdbcTemplate简介 Spring JdbcTemplate的出现是为了弥补原生JDBC在编码上的繁琐,它通过模板方法模式,将SQL执行...
使用Spring的JdbcTemplate调用Oracle的存储过程
使用Spring的JdbcTemplate实现分页功能
在本文中,我们将深入探讨Spring框架中的一个核心组件——JdbcTemplate。JdbcTemplate是Spring提供的一种数据库操作工具,它简化了数据库访问,使开发者能够编写出更健壮、更易于维护的代码,避免了手动处理JDBC连接...
在Spring中,JdbcTemplate就是一个典型的模板类,它实现了数据库操作的基本流程,如创建Connection、PreparedStatement、处理结果集等。用户可以通过扩展或自定义模板方法来实现特定的数据库操作逻辑。 **3. 回调...
1. **SpringJdbcTemplate的基本概念** SpringJdbcTemplate是一个模板类,它提供了大量的方法来执行SQL查询、更新、存储过程等操作。这些方法会自动处理JDBC相关的资源关闭、异常转换等细节,使得代码更加整洁和健壮...
### Spring中的JdbcTemplate #### JdbcTemplate概述 JdbcTemplate是Spring框架提供的一种用于简化JDBC编程的对象。通过封装原生的JDBC API,JdbcTemplate不仅提高了代码的可读性和可维护性,还帮助开发者避免了...
spring 中对大数据的处理,包括clob,blob的数据。比之jdbc下简便很多。
Struts2、Spring和Spring JDBC Template是Java Web开发中常用的三个框架,它们分别负责不同的职责。Struts2作为MVC(Model-View-Controller)框架,主要处理前端请求和业务逻辑;Spring则是一个全面的后端框架,提供...
Struts、Spring 和 JDBCTemplate 是三个在 Java Web 开发中常用的框架和技术,它们结合使用可以构建出高效且灵活的企业级应用程序。在这个“Struts+Spring+JdbcTemplate Demo”中,我们将探讨这三个组件如何协同工作...
在Spring配置文件中,我们需要定义一个`JdbcTemplate` bean,如下所示: ```xml <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> ``` 其中,`dataSource`是指向数据库连接池的...
`Spring-JdbcTemplate` 是 Spring 框架中的一个核心模块,主要用于简化数据库操作,提供了强大的数据访问功能。它通过模板方法设计模式封装了 SQL 的执行,使得开发者无需直接与 JDBC API 打交道,从而降低了数据库...
配制Spring事务和JdbcTemplate使用 配制Spring事务和JdbcTemplate使用
Spring的JdbcTemplate是Spring框架中用于简化数据库操作的工具类,它是基于JDBC但又抽象出了一层,避免了直接与数据库驱动API交互,从而提高了代码的可读性和可维护性。本文将深入探讨Spring JdbcTemplate的常用方法...
Spring 框架 JdbcTemplate 类中查询方法介绍 JdbcTemplate 是 Spring 框架中 org.springframework.jdbc.core 包提供的 JDBC 模板类,它是核心类,其他模板类都是基于它封装完成的。JdbcTemplate 类主要提供四类方法...
Spring的JdbcTemplate是Spring框架中的一个核心组件,用于简化数据库操作。它提供了一种模板方法模式,抽象出常见的JDBC代码,使得开发者可以避免编写大量的重复性代码,从而更加专注于业务逻辑。本项目是对Spring ...
Spring的JdbcTemplate是Spring框架中的一个核心组件,用于简化数据库操作。它提供了一种模板方法模式,抽象出了一些常见的数据库访问任务,使得开发者无需关注低级的JDBC细节,如打开和关闭连接、处理结果集等,从而...
使用Spring的JdbcTemplate和BeanPropertyRowMapper完成的JDBC我的实例 博文链接:https://zmx.iteye.com/blog/373454
在本项目中,开发者结合了Spring Security 3.1,Spring,Servlet以及JdbcTemplate来构建一个安全的Web应用。 Spring框架是Java开发中不可或缺的一部分,它简化了应用开发并提供了诸如依赖注入、面向切面编程等核心...