|
@@ -22,6 +22,7 @@ import java.io.Serializable;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
@@ -123,8 +124,9 @@ public abstract class BaseServiceImpl<PK extends Serializable, T> implements Bas
|
|
|
StringBuffer sql=new StringBuffer();
|
|
|
Map<Y,Z> result=new HashMap();
|
|
|
try {
|
|
|
+ Connection connection = sqlSessionFactory.openSession().getConnection();
|
|
|
sql.append("select ").append(columnKey).append(",").append(columnValue).append(" FROM ").append(tableName).append(" WHERE ").append(columnKey).append(" IN (").append(StringUtils.join(ids, ",")).append(")");
|
|
|
- PreparedStatement ps = sqlSessionFactory.openSession().getConnection().prepareStatement(sql.toString());
|
|
|
+ PreparedStatement ps = connection.prepareStatement(sql.toString());
|
|
|
ResultSet resultSet = ps.executeQuery();
|
|
|
while (resultSet.next()){
|
|
|
Y key;
|
|
@@ -145,6 +147,15 @@ public abstract class BaseServiceImpl<PK extends Serializable, T> implements Bas
|
|
|
}
|
|
|
result.put(key, value);
|
|
|
}
|
|
|
+ if(resultSet!=null){
|
|
|
+ resultSet.close();
|
|
|
+ }
|
|
|
+ if(ps!=null){
|
|
|
+ ps.close();
|
|
|
+ }
|
|
|
+ if(connection!=null){
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -157,12 +168,22 @@ public abstract class BaseServiceImpl<PK extends Serializable, T> implements Bas
|
|
|
StringBuffer sql=new StringBuffer();
|
|
|
Map<String, String> result=new HashMap();
|
|
|
try {
|
|
|
- sql.append("select ").append(columnKey).append(",").append(columnValue).append(" FROM ").append(tableName).append(" WHERE ").append(columnKey).append(" IN (").append(StringUtils.join(ids, ",")).append(")");
|
|
|
- PreparedStatement ps = sqlSessionFactory.openSession().getConnection().prepareStatement(sql.toString());
|
|
|
+ Connection connection = sqlSessionFactory.openSession().getConnection();
|
|
|
+ sql.append("SELECT ").append(columnKey).append(",").append(columnValue).append(" FROM ").append(tableName).append(" WHERE ").append(columnKey).append(" IN (").append(StringUtils.join(ids, ",")).append(")");
|
|
|
+ PreparedStatement ps = connection.prepareStatement(sql.toString());
|
|
|
ResultSet resultSet = ps.executeQuery();
|
|
|
while (resultSet.next()){
|
|
|
result.put(resultSet.getString(1), resultSet.getString(2));
|
|
|
}
|
|
|
+ if(resultSet!=null){
|
|
|
+ resultSet.close();
|
|
|
+ }
|
|
|
+ if(ps!=null){
|
|
|
+ ps.close();
|
|
|
+ }
|
|
|
+ if(connection!=null){
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|