master
erzhongxmu 2020-04-25 16:44:13 +08:00
parent 6719151bb6
commit 756ec57b90
2 changed files with 21 additions and 16 deletions

View File

@ -343,10 +343,10 @@
<artifactId>ojdbc14</artifactId>
<version>${ojdbc14.version}</version>
</dependency>
<!-- jtds for mssql/db2 <dependency> <groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId> <version>${jtds.version}</version> <scope>runtime</scope>
<!-- jtds for mssql/db2 <dependency> <groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId> <version>${jtds.version}</version> <scope>runtime</scope>
</dependency> -->
<!-- h2 <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId>
<!-- h2 <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId>
<version>${h2.version}</version> <scope>test</scope> </dependency> -->
<!-- postgresql -->
<dependency>
@ -1089,4 +1089,4 @@
</testResources>
</build>
</project>
</project>

View File

@ -1,5 +1,6 @@
package org.jeecgframework.core.common.dao.jdbc;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
@ -20,12 +21,12 @@ import org.springframework.util.Assert;
*/
@SuppressWarnings("unchecked")
public class SimpleJdbcTemplate {
protected final Log logger = LogFactory.getLog(getClass());
protected JdbcTemplate jdbcTemplate;
protected NamedParameterJdbcTemplate namedJdbcTemplate;
protected SimpleJdbcInsert simpleJdbcInsert;
public SimpleJdbcTemplate(DataSource dataSource){
jdbcTemplate=new JdbcTemplate(dataSource);
@ -54,7 +55,7 @@ public class SimpleJdbcTemplate {
return null;
}
}
/**
* sql
* @param sql(select * from tb where id=:id)
@ -78,7 +79,7 @@ public class SimpleJdbcTemplate {
return null;
}
}
/**
* sql
* @param sql(select count(*) from tb where id=:id)
@ -89,17 +90,21 @@ public class SimpleJdbcTemplate {
try{
Assert.hasText(sql,"sql语句不正确!");
if(parameters!=null){
return namedJdbcTemplate.queryForObject(sql, parameters,long.class);
if(parameters!=null&&parameters.size()>0){
Object res = namedJdbcTemplate.queryForObject(sql, parameters,BigInteger.class);
BigInteger a = new BigInteger(res.toString());
return a.longValue();
}else{
return jdbcTemplate.queryForObject(sql,long.class);
Object res = jdbcTemplate.queryForObject(sql,BigInteger.class);
BigInteger a = new BigInteger(res.toString());
return a.longValue();
}
}catch (Exception e) {
return (long)0;
}
}
/**
* sqlMap,Bean使MapKey,value
* @param sql(select count(*) from tb where id=:id)
@ -118,7 +123,7 @@ public class SimpleJdbcTemplate {
return null;
}
}
/**
* sqlMap
* @see findForMap
@ -138,7 +143,7 @@ public class SimpleJdbcTemplate {
return null;
}
}
/**
* insertupdatedelete<br>
* insert into users (name,login_name,password) values(:name,:loginName,:password)<br>
@ -170,7 +175,7 @@ public class SimpleJdbcTemplate {
return jdbcTemplate.update(sql);
}
}
/*public long executeForObjectReturnPk(final String sql,Object bean){
Assert.hasText(sql,"sql语句不正确!");
if(bean!=null){
@ -179,7 +184,7 @@ public class SimpleJdbcTemplate {
return jdbcTemplate.update(sql);
}
}*/
/*
*
* update t_actor set first_name = :firstName, last_name = :lastName where id = :id