读取配置文件类

package com.eshore.ismp.contract.sql;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; public class SQLPropertyConfigurer {
private Logger logger = LoggerFactory.getLogger(SQLPropertyConfigurer.class);
private static final Properties properties =new Properties();
private String path; private SQLPropertyConfigurer(String path) {
this.path = path;
load();
} /**
*
* //DESC 获取sql语句
* @time: 2016年6月16日 下午12:12:48
* @throws
*/
private void load() {
if (null != properties) {
InputStream in = null;
try {
/* 检测是否需要从classpath下进行sql配置文件的读取 */
if (path.indexOf("classpath:") != -1) {
/* 从classpath下获取sql配置文件 */
in = this.getClass().getResourceAsStream("/" + path.split("classpath:")[1]);
}
if (null == in) {
/* 从文件路径获取sql配置文件 */
in = new FileInputStream(path);
properties.load(in);
} else {
properties.load(in);
}
logger.info("load sql file success");
} catch (FileNotFoundException e) {
logger.error("sqlfile is not found:",e);
} catch (IOException e) {
logger.error("read sqlfile error:",e);
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
logger.error("read sqlfile error:",e);
}
}
}
}
} /**
*
* //DESC (这里用一句话描述这个方法的作用)
* @time: 2016年6月6日 上午10:25:55
* @param key
* @param routeKey
* @return
* @throws
*/
public static String getSql(String key) {
String sql = null;
if (null != properties) {
sql = properties.getProperty(key);
}
return sql;
}
}

  

spring配置文件

<bean id="SQLPropertyConfigurer" class="com.eshore.ismp.contract.sql.SQLPropertyConfigurer">
<constructor-arg name="path" value="classpath:sql.properties" />
</bean>

 

数据库代码配置文件

getId=CALL getId(?,?,?)
insertContract=insert into T_PRODUCT_CONTRACT (id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
insertContractHisByServNbr=insert into T_PRODUCT_CONTRACT_HIS (id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
queryContractByServNbr=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where serv_nbr=? and city_id=?
queryNonormalByServNbr=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where serv_nbr=? and city_id=? and state_id IN (0,1,2,11,12,14)
queryContractByServNbrAndServNbrParent=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where serv_nbr=? and serv_nbr_parent=? and city_id=?
queryContractByServNbrAndProductSpecId=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where serv_nbr\=? and product_spec_id\=? and city_id\=?
queryContractByBnetId=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where bnet_id\=? and city_id\=?
queryContractByBnetIdAndProductSpecId=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where bnet_id\=? and product_spec_id\=? and city_id\=?
queryContractByServNbrParent=select id, bnet_id,product_spec_id,state_id,offering_id,accept_number,offering_spec_id,serv_nbr_parent,serv_nbr,acc_nbr,node_id,sys_id,city_id,create_time,modify_time from T_PRODUCT_CONTRACT where serv_nbr_parent\=? and city_id\=?
updateContractStatusByServNbr=update T_PRODUCT_CONTRACT set state_id=? where serv_nbr=? and city_id=?
updateContractStatusByServNbrAndProductSpecId=update T_PRODUCT_CONTRACT set state_id=? where serv_nbr=? and product_spec_id=? and city_id=?
updateAccNbr=update T_PRODUCT_CONTRACT set acc_nbr=? where serv_nbr=? and city_id=?
updateContractByServNbr=update T_PRODUCT_CONTRACT set

 

java代码

	@Override
public List<Contract> queryByServNbrAndServNbrParent(String servNbr,
String servNbrParent, int cityId) {
RowMapper<Contract> rowMapper = new ContractRowMapper();
return jdbcTemplate.query(SQLPropertyConfigurer.getSql("queryContractByServNbrAndServNbrParent"), new Object[]{servNbr,servNbrParent,cityId}, new int[]{java.sql.Types.VARCHAR,java.sql.Types.VARCHAR,java.sql.Types.INTEGER}, rowMapper ); } @Override
public List<Contract> queryUserOrderData(String bnetId, int cityId) {
RowMapper<Contract> rowMapper = new ContractRowMapper();
return jdbcTemplate.query(SQLPropertyConfigurer.getSql("queryContractInfoBybnetIdAndCityId"), new Object[]{bnetId,cityId}, new int[]{java.sql.Types.VARCHAR,java.sql.Types.INTEGER}, rowMapper );
}

  

 

 

spring jdbc分离数据库代码和java代码的更多相关文章

  1. Android学习笔记_32_通过WebView实现JS代码与Java代码互相通信

    webview两种实现方法,覆盖onKeyDown()方法 缓存 WebSettings应用注意的几个问题 1.要实现JS代码与Java代码互相通信,需要通过Android的WebView控件,在视图 ...

  2. C代码调用Java代码

    C代码调用Java代码应用场景 复用已经存在的java代码 c语言需要给java一些通知 c代码不方便实现的逻辑(界面) 反射 //1.加载类字节码 Class clazz = Demo.class. ...

  3. Java Spring JDBC访问数据库

    一.首先采用org.springframework.jdbc.datasource.DriverManagerDataSource类进行实现 1.applicationContext.xml配置如下: ...

  4. Spring学习(四)——使用Spring JDBC访问数据库

    本篇我们将在上一篇http://www.cnblogs.com/wenjingu/p/3824294.html的Demo程序的基础上增加数据持久层和业务层,实现登录验证功能. 1.修改gradle文件 ...

  5. Spring入门(十五):使用Spring JDBC操作数据库

    在本系列的之前博客中,我们从没有讲解过操作数据库的方法,但是在实际的工作中,几乎所有的系统都离不开数据的持久化,所以掌握操作数据库的使用方法就非常重要. 在Spring中,操作数据库有很多种方法,我们 ...

  6. Spring JDBC主从数据库配置

    通过昨天学习的自定义配置注释的知识,探索了解一下web主从数据库的配置: 背景:主从数据库:主要是数据上的读写分离: 数据库的读写分离的好处? 1. 将读操作和写操作分离到不同的数据库上,避免主服务器 ...

  7. Spring JDBC主从数据库访问配置

    通过昨天学习的自定义配置注释的知识,探索了解一下web主从数据库的配置: 背景:主从数据库:主要是数据上的读写分离: 数据库的读写分离的好处? 1. 将读操作和写操作分离到不同的数据库上,避免主服务器 ...

  8. Android NDK开发(五)--C代码回调Java代码【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41862479 在上篇博客里了解了Java层是怎样传递数据到C层代码,并且熟悉了大部 ...

  9. 【持续更新】把.net代码转换为java代码的注意事项

    国内大多数大学的软件相关专业大多强制学生学习c和Java,但.net 的几个语言可以说是选学的. 由于visual studio在windows平台上使用相对方便,一些同学会在上大学的Java课之前自 ...

随机推荐

  1. 不得不玩玩NHibernate

    1.0=>前言 放着好好的EF不用,为什么要来玩NHibernate了?那是因为现在的工作内容就是维护一个比较老的项目,第一版是公司找外包做的,跟数据库打交道这块用的NHibernate,虽然都 ...

  2. C#读取网络流,读取网络上的js文件

    写博客的目的就是让其他人少走弯路. C#读取网络上的流和js文件出现的问题 一开始看了今天博客园上的推荐文章,用C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子),然 ...

  3. 误人子弟的网络,谈谈HTTP协议中的短轮询、长轮询、长连接和短连接

    引言 最近刚到公司不到一个月,正处于熟悉项目和源码的阶段,因此最近经常会看一些源码.在研究一个项目的时候,源码里面用到了HTTP的长轮询.由于之前没太接触过,因此LZ便趁着这个机会,好好了解了一下HT ...

  4. [BZOJ1061][Noi 2008]志愿者招募(网络流)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1061 分析: 神题不解释,只能欣赏:https://www.byvoid.com/bl ...

  5. 同态加密-Homomorphic encryption

    同态加密(Homomorphic encryption)是一种加密形式,它允许人们对密文进行特定的代数运算得到仍然是加密的结果,将其解密所得到的结果与对明文进行同样的运算结果一样.换言之,这项技术令人 ...

  6. BroadcastReceiver之有序广播

    有序广播可以按一定的优先级进行传播 首先进行发送广播 public void click(View v){ Intent intent = new Intent(); intent.setAction ...

  7. Python学习教程

    Python语法简洁清晰,特色之一是强制用空白符(white space)作为语句缩进.Python具有丰富和强大的库.它常被昵称为胶水语言,能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地 ...

  8. java 中hashmap和hashtable的区别

    1.hashmap是线程不安全的,能够有key,value能有null hashtable是线程安全的,key,value不能有null

  9. 一、项目基础架构(附GitHub地址)——以ABP为基础架构的一个中等规模的OA开发日志

    前言: 最近园子里ABP炒的火热.看了几篇对于ABP的介绍后,深感其设计精巧,实现优雅.个人感觉,ABP或ABP衍生品的架构设计,未来会成为中型Net项目的首选架构模式.如果您还不了解ABP是什么,有 ...

  10. 强连通 HDU 3861

    t个样例 n个点m条边 分成一些区 2个点互相能到达必须分在一个区 一个区中任何2个点可以u->v 或者v->u 任何点都要有自己的区 求最小的区的数目 强联通缩点 成新图 二分匹配 求最 ...