我使用Spring进行数据库操作。现在我救我的SQL查询到一个XML文件中,就像这样:将sql查询保存到外部文件中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>This query returns something extremely useful.
</comment>
<entry key="date.sql">
"update something set time = ? where sharedkey = ?"
</entry>
</properties>
而在JdbcTemplate的,我有这样的:
public Properties readProperties(String xmlFileName) throws Exception {
Properties properties = new Properties();
InputStream is = this.getClass().getClassLoader().getResourceAsStream(xmlFileName);
properties.loadFromXML(is);
return properties;
}
public void updateDate(){
properties = readProperties("queries.xml");
sqlQuery = properties.getProperty("date.sql");
jdbcTemplateObject.update(sqlQuery,new Object[] {time,token});
}
工作,但我认为这是不是最好的解决办法,我怎么能与春天?还是有其他的库?
_我觉得它不是最好的解决方案_你是什么意思,从这个角度来看,你问这个问题? – 2015-03-03 08:58:25
@HimanshuBhardwaj我想从代码 – 2015-03-03 09:00:28
中分离查询,通常我们使用Spring与hibernate或spring一起使用JPA进行数据库调用。是否使用spring MVC? – SpringLearner 2015-03-03 09:00:51