数据源DBAccess02

private static String getSql(final String sql, String sqlPre)
{
String maxRow = FileManager.getESBProperty("MAX_ROW");
if ((maxRow != null) && (!"".equals(maxRow)))
{
int pos = sql.indexOf("order by");
if (pos == -1)
{
pos = sql.indexOf("ORDER BY");
if (pos == -1)
pos = sql.indexOf("group by");
if (pos == -1)
pos = sql.indexOf("ORDER BY");
}
if (pos > 0)
{
sqlPre = sql.substring(0, pos - 1) + " and rownum < " + maxRow
+ " " + sql.substring(pos);
}
}
return sqlPre;
}

/*
* 简单的通用数据库Insert/Update方法,提供给非标准JAVA客户端使用(入参只支持String)
*
* @param sql sql语句,参数用?
*
* @param param 参数值,参数值的顺利必须与sql语句中的参数(?)匹配(使用||分隔的字符串)
*
* @return void
*/
public static void execSQL(String sql, String param)
{
String[] tmp = param.split("\\|\\|");
ArrayList<String> paramList = new ArrayList<String>();
for (int i = 0; i < tmp.length; i++)
{
paramList.add(tmp[i]);
}
execSQL(sql, paramList);
}

/*
* 简单的通用数据库Insert/Update方法
*
* @param sql sql语句,参数用?
*
* @param param 参数值,参数值的顺利必须与sql语句中的参数(?)匹配
*
* @return void
*/
public static void execSQL(final String sql, List<String> param)
{
logger.info("Get connection begin ...");
Connection conn = getConnection();
logger.info("Get connection Successful.");
PreparedStatement ps = null;
try
{
logger.info("Prepare sql statement:[" + sql + "]");
ps = conn.prepareStatement(sql);

logger.info("Prepare sql parameters:" + param.toString());
for (int i = 0; i < param.size(); i++)
{
ps.setString(i + 1, (String) param.get(i));
}
logger.info("Execute sql begin ...");
ps.execute();
logger.info("Execute sql Successful.");
}
catch (Exception e)
{
logger.error("DataBase execute exception! Message:" + e.toString()
+ "\n\t\tSqlText: " + sql + "\n\t\tparam: "
+ param.toString());
throw new BaseException(e);
}
finally
{
if (null != ps)
{
try
{
ps.close();
logger.info("Close PreparedStatement Successful.");
}
catch (SQLException e)
{
logger.error("Close PreparedStatement error! Message:"
+ e.toString());
throw new BaseException(e);
}
}
if (null != conn)
{
try
{
conn.close();
logger.info("Close Connection Successful.");
}
catch (SQLException e)
{
logger.error("Close connection error! message:"
+ e.toString());
throw new BaseException(e);
}
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值