Java Code Examples for org.springframework.jdbc.core.JdbcTemplate#getDataSource()
The following examples show how to use
org.springframework.jdbc.core.JdbcTemplate#getDataSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootDataJdbcApplication.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
private void printDataSourceInfo(JdbcTemplate jdbcTemplate) throws SQLException { DataSource dataSource = jdbcTemplate.getDataSource(); Connection connection; if (dataSource != null) { connection = dataSource.getConnection(); } else { log.error("Get dataSource failed!"); return; } if (connection != null) { log.info("DataSource Url: {}", connection.getMetaData().getURL()); } else { log.error("Connect to datasource failed!"); } }
Example 2
Source File: SpringBootDataCacheJetcacheApplication.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
public void printDataSourceInfo(JdbcTemplate jdbcTemplate) throws SQLException { DataSource dataSource = jdbcTemplate.getDataSource(); Connection connection; if (dataSource != null) { connection = dataSource.getConnection(); } else { log.error("获取 DataSource 失败"); return; } if (connection != null) { log.info("DB URL: {}", connection.getMetaData().getURL()); } else { log.error("获取 Connection 失败"); } }
Example 3
Source File: SpringBootDataJdbcMultiDataSourceApplication.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
private void printDataSourceInfo(JdbcTemplate jdbcTemplate) throws SQLException { DataSource dataSource = jdbcTemplate.getDataSource(); Connection connection; if (dataSource != null) { connection = dataSource.getConnection(); } else { log.error("Get dataSource failed!"); return; } if (connection != null) { log.info("DataSource Url: {}", connection.getMetaData().getURL()); } else { log.error("Connect to datasource failed!"); } }
Example 4
Source File: SpringBootDataCacheApplication.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
public void printDataSourceInfo(JdbcTemplate jdbcTemplate) throws SQLException { DataSource dataSource = jdbcTemplate.getDataSource(); Connection connection; if (dataSource != null) { connection = dataSource.getConnection(); } else { log.error("获取 DataSource 失败"); return; } if (connection != null) { log.info("DB URL: {}", connection.getMetaData().getURL()); } else { log.error("获取 Connection 失败"); } }
Example 5
Source File: DynamicDBUtil.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的Update * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static int updateByHash(final String dbKey, String sql, HashMap<String, Object> data) { int effectCount; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); effectCount = namedParameterJdbcTemplate.update(sql, data); return effectCount; }
Example 6
Source File: DynamicDBUtil.java From jeecg with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 返回单列数据list * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param clazz 类型Long、String等 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static <T> List<T> findListByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data){ List<T> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data, clazz); return list; }
Example 7
Source File: DynamicDBUtil.java From jeecg with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static List<Map<String, Object>> findListByHash(final String dbKey, String sql, HashMap<String, Object> data){ List<Map<String, Object>> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data); return list; }
Example 8
Source File: DynamicDBUtil.java From jeecg with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的Update * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static int updateByHash(final String dbKey, String sql, HashMap<String, Object> data){ int effectCount = 0; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); effectCount = namedParameterJdbcTemplate.update(sql, data); return effectCount; }
Example 9
Source File: MySQLTempStatTableCreator.java From olat with Apache License 2.0 | 5 votes |
/** set via spring **/ public void setJdbcTemplate(final JdbcTemplate jdbcTemplate) { jdbcTemplate_ = jdbcTemplate; final DataSource dataSource = jdbcTemplate == null ? null : jdbcTemplate.getDataSource(); Connection connection = null; try { if (dataSource != null) { connection = dataSource.getConnection(); } } catch (final SQLException e) { log.warn("setJdbcTemplate: SQLException while trying to get connection for logging", e); } log.info("setJdbcTemplate: jdbcTemplate=" + jdbcTemplate + ", dataSource=" + dataSource + ", connection=" + connection); }
Example 10
Source File: MySQLTempStatTableCreator.java From olat with Apache License 2.0 | 5 votes |
/** set via spring **/ public void setJdbcTemplate(final JdbcTemplate jdbcTemplate) { jdbcTemplate_ = jdbcTemplate; final DataSource dataSource = jdbcTemplate == null ? null : jdbcTemplate.getDataSource(); Connection connection = null; try { if (dataSource != null) { connection = dataSource.getConnection(); } } catch (final SQLException e) { log.warn("setJdbcTemplate: SQLException while trying to get connection for logging", e); } log.info("setJdbcTemplate: jdbcTemplate=" + jdbcTemplate + ", dataSource=" + dataSource + ", connection=" + connection); }
Example 11
Source File: DynamicDBUtil.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 返回单列数据list * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param clazz 类型Long、String等 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static <T> List<T> findListByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) { List<T> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data, clazz); return list; }
Example 12
Source File: DynamicDBUtil.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static List<Map<String, Object>> findListByHash(final String dbKey, String sql, HashMap<String, Object> data) { List<Map<String, Object>> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data); return list; }
Example 13
Source File: DynamicDBUtil.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的Update * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static int updateByHash(final String dbKey, String sql, HashMap<String, Object> data) { int effectCount; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); effectCount = namedParameterJdbcTemplate.update(sql, data); return effectCount; }
Example 14
Source File: DynamicDBUtil.java From teaching with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 返回单列数据list * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param clazz 类型Long、String等 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static <T> List<T> findListByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) { List<T> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data, clazz); return list; }
Example 15
Source File: DynamicDBUtil.java From teaching with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static List<Map<String, Object>> findListByHash(final String dbKey, String sql, HashMap<String, Object> data) { List<Map<String, Object>> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data); return list; }
Example 16
Source File: DynamicDBUtil.java From teaching with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的Update * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static int updateByHash(final String dbKey, String sql, HashMap<String, Object> data) { int effectCount; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); effectCount = namedParameterJdbcTemplate.update(sql, data); return effectCount; }
Example 17
Source File: DynamicDBUtil.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 返回单列数据list * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param clazz 类型Long、String等 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static <T> List<T> findListByHash(final String dbKey, String sql, Class<T> clazz, HashMap<String, Object> data) { List<T> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data, clazz); return list; }
Example 18
Source File: DynamicDBUtil.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 支持miniDao语法操作的查询 * * @param dbKey 数据源标识 * @param sql 执行sql语句,sql支持minidao语法逻辑 * @param data sql语法中需要判断的数据及sql拼接注入中需要的数据 * @return */ public static List<Map<String, Object>> findListByHash(final String dbKey, String sql, HashMap<String, Object> data) { List<Map<String, Object>> list; JdbcTemplate jdbcTemplate = getJdbcTemplate(dbKey); //根据模板获取sql sql = FreemarkerParseFactory.parseTemplateContent(sql, data); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); list = namedParameterJdbcTemplate.queryForList(sql, data); return list; }
Example 19
Source File: MicroMetaDao.java From nh-micro with Apache License 2.0 | 4 votes |
public DataSource getMicroDataSource(){ //JdbcTemplate retTemplate=(JdbcTemplate) MicroDbHolder.getDbSource(dbName); JdbcTemplate retTemplate=(JdbcTemplate) getMicroJdbcTemplate(dbName); return retTemplate.getDataSource(); }
Example 20
Source File: MicroMetaDao.java From nh-micro with Apache License 2.0 | 4 votes |
public DataSource getMicroDataSource(){ //JdbcTemplate retTemplate=(JdbcTemplate) MicroDbHolder.getDbSource(dbName); JdbcTemplate retTemplate=(JdbcTemplate) getMicroJdbcTemplate(dbName); return retTemplate.getDataSource(); }