总结java程序中操作Oracle数据库的常用操作1

//
/ Martin总结Oarcle常用功能 2010-10-28 ///
//
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
//
//从Oracle数据库获取时间:
Timestamp ts = rs.getTimestamp("ttime");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String time = sdf.format(ts);
/
//向Oracle数据库中添加Timestamp类型的数据
//PreparedStatement pstmt
Timestamp now = new Timestamp(System.currentTimeMillis());
pstmt.setTimestamp(3,now);
/
//从Oracle读取出Blob类型的数据
Blob blob = rs.getBlob("content");
String content="";
if(blob!=null){
InputStream in = blob.getBinaryStream();
//把in的字节流写入String
byte[] buff=new byte[1024];
while(in.read(buff)>0){
content = content+new String(buff);
}
}else{
content = "空值";
}
/
//PreparedStatement pstmt
//uploadfile:文件路径
InputStream in = new FileInputStream(new File(uploadfile));
pstmt.setBinaryStream(4, in, in.available());
/
//更新Oracle数据表记录:
public boolean update(Map<String, String> map) {
boolean isSuccess = false;
Connection con = null;
PreparedStatement prepar = null;
ResultSet rs = null;
String sql = "update personcreditcomplain t set t.jgbm=?,t.jbtime=?,t.bjtime=?,t.clyj=?,t.dbzt=?,t.sfsh=? where id=?";

try {
con = ConnectionPool.getConnection();
prepar = con.prepareStatement(sql);
prepar.setString(1, ParseParameter.nullPares(map.get("jgbm"), "")); // 监管部门
prepar.setString(2, ParseParameter.nullPares(map.get("jbtime"), "")); // 交办时间
prepar.setString(3, ParseParameter.nullPares(map.get("bjtime"), "")); // 办结时间
prepar.setString(4, ParseParameter.nullPares(map.get("clyj"), "")); // 监管部门处理意见
prepar.setString(5, map.get("dbzt")); // 督办状态
prepar.setString(6, map.get("sfsh")); // 是否审核
prepar.setString(7, map.get("id"));
int n = prepar.executeUpdate();
if (n > 0) {
isSuccess = true;
}
con.commit();
} catch (SQLException e) {
LOG.error(e.getMessage());
e.printStackTrace();
try {
con.rollback();
} catch (SQLException e1) {
LOG.error(e1.getMessage());
}
} finally {
ConnectionPool.closeResultSet(rs);
ConnectionPool.closeStatement(prepar);
ConnectionPool.closeConnection(con);
}
return isSuccess;
}
/
//Oracle分页:
String sql = "SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM personcreditcomplain "
+ " order by id desc) A WHERE ROWNUM <="
+ (curpage * pageSize)
+ ") WHERE RN >= "
+ ((curpage - 1) * pageSize + 1) + " order by id DESC";
/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值