Spring JDBC detaches database code and Java code

Source: Internet
Author: User

Read Profile class

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);p rivate static Final Properties Properties =new properties ();p rivate String path;private Sqlpropertyconfigurer (String path) {This.path = Path;load ();} /** * *//DESC Get SQL statement * @time: June 16, 2016 PM 12:12:48 * @throws */private void load () {if (null! = properties) {Inputstre  AM in = null;try {/* detects whether a SQL configuration file needs to be read from Classpath */if (Path.indexof ("classpath:")! =-1) {/* Get SQL configuration file from classpath */in = This.getclass (). getResourceAsStream ("/" + Path.split ("classpath:") [1]);} if (null = = in) {/* Gets the SQL configuration file from the file path */in = new FileInputStream (path);p roperties.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 (here in a word describing the effect of this method) * @time: June 6, 2016 morning 10:25:55 * @param key * @param routekey * @return * @throws */publi C Static string GetSQL (String key) {String sql = Null;if (null! = properties) {sql = Properties.getproperty (key);} return SQL;}}

  

Spring configuration file

<bean id= "Sqlpropertyconfigurer" class= "Com.eshore.ismp.contract.sql.SQLPropertyConfigurer" >< Constructor-arg name= "path" value= "Classpath:sql.properties"/></bean>

 

Database Code configuration file

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 code

@Overridepublic 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);} @Overridepublic 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 detaches database code and Java code

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.