用线程入库的操作 OperateDB 02

/**
* 根据TableName_Field生成 PreparedStatement的SQL,生成的sql语句:insert
* 2012-1-7,Xgw123485
*/
private static String getPstatementsql(TableName_Field table)
{
StringBuffer insertBuffer = new StringBuffer(50);
StringBuffer valueBuffer = new StringBuffer(20);

insertBuffer.append("insert into ").append(table.getTableName())
.append("(");
valueBuffer.append("values (");
// 生成字段名对应的SQL
for (EsbTableField esbTableField : table.getList())
{
insertBuffer.append(esbTableField.getFieldName()).append(",");
valueBuffer.append("?,");
}
// 先删除insertBuffer中的最后一个字符,加上valueBuffer去掉最后一个字符的串
return insertBuffer
.deleteCharAt(insertBuffer.length() - 1)
.append(")")
.append(valueBuffer.deleteCharAt(valueBuffer.length() - 1)
.toString()).append(")").toString();
}

/**
* seqid获取临时规避方案, 由yyyymmdd + 8位码组成,sequence需要建成可循环的 2012-1-7,Xgw123485
*/
public static String[] getSeq_id()
{
String[] seq = new String[100];
Connection connection = ConnectionTools.getConnection();
// 如果取不到数据库连接则抛出异常
if (connection == null)
{
logger.error("Can't get fetch Connection");
return null;
}
PreparedStatement pstatement = null;
ResultSet rs = null;
try
{
pstatement = connection
.prepareStatement("SELECT TO_CHAR(cle_log_seq_id.nextval,'09999999') "
+ "as seq_id FROM DUAL CONNECT BY LEVEL <=100");
rs = pstatement.executeQuery();
int index = 0;
while (rs.next())
{
seq[index++] = rs.getString("seq_id");
}
}
catch (Exception e)
{
logger.error("Get seq_id fail", e);
}
finally
{
ConnectionTools.closeResult(rs);
ConnectionTools.closeStmt(pstatement);
ConnectionTools.closeConn(connection);
}
return seq;
}

/**
* seqid获取临时规避方案, 由yyyymmdd + 14位码组成,sequence需要建成可循环的 2012-1-7,Xgw123485
*/
public static String[] getTrancking_id()
{
String[] seq = new String[100];
Connection connection = ConnectionTools.getConnection();
// 如果取不到数据库连接则抛出异常
if (connection == null)
{
logger.error("Can't get fetch Connection");
return null;
}
PreparedStatement pstatement = null;
ResultSet rs = null;
try
{
pstatement = connection
.prepareStatement("SELECT TO_CHAR(cle_log_trancking_id.nextval,'09999999999999')"
+ "as seq_id FROM DUAL CONNECT BY LEVEL<=100");
rs = pstatement.executeQuery();
int index = 0;
while (rs.next())
{
seq[index++] = rs.getString("seq_id");
}
}
catch (Exception e)
{
logger.error("Get seq_id fail", e);
}
finally
{
ConnectionTools.closeResult(rs);
ConnectionTools.closeStmt(pstatement);
ConnectionTools.closeConn(connection);
}

return seq;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值