HTML数据保存 Oracle CLOB大对象操作
2010-11-08 22:59
519 查看
public User getUser(int id) throws ClassNotFoundException, SQLException { Connection conn = DBConnection.getConnection(); User user = new User(); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from userinfo where id ="+id); if (rs.next()) { user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setUserpass(rs.getString("userpass")); java.sql.Clob clob = rs.getClob("userinfo"); Reader inStream = clob.getCharacterStream(); char[] c = new char[(int) clob.length()]; inStream.read(c); String data = new String(c); user.setUserinfo(data); inStream.close(); } rs.close(); stmt.close(); } catch (Exception e) { System.out.println(" Error:"+e.getMessage()); }finally{ conn.close(); } return user; } public int addUser(User user) throws ClassNotFoundException, SQLException { Connection conn = DBConnection.getConnection(); String sql=""; int id = 0; try { PreparedStatement pstmt=null; ResultSet rst=null; conn.setAutoCommit(false); oracle.sql.CLOB clob=null; sql = "select sequenceDemo.nextval from dual"; pstmt = conn.prepareStatement(sql); rst=pstmt.executeQuery(); if(rst.next()){ id = (int)rst.getInt(1); } pstmt.close(); //添加null Clob sql = "insert into userinfo(id,username,userpass,userinfo) values (?,?,?,empty_clob())"; pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); pstmt.setString(2, user.getUsername()); pstmt.setString(3, user.getUserpass()); pstmt.executeUpdate(); pstmt.close(); //获取修改--锁 sql = "select userinfo from userinfo where id= ? for update"; pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); rst=pstmt.executeQuery(); if(rst.next()){ clob=(CLOB)rst.getClob(1); } pstmt.close(); //获得clob对象的输出流 PrintWriter pw=new PrintWriter(clob.getCharacterOutputStream()); pw.write(user.getUserinfo()); pw.flush(); //更新clob对象 sql="UPDATE userinfo set userinfo =? where id=?"; pstmt=conn.prepareStatement(sql); pstmt.setClob(1, clob); pstmt.setInt(2, id); pstmt.executeUpdate(); conn.commit(); pw.close(); pstmt.close(); }catch (Exception e) { System.out.println(" Error:"+e.getMessage()); }finally{ conn.close(); } return id; }
相关文章推荐
- oracle对大对象类型操作:blob,clob,nclob
- 密码对象登陆界面的数据保存回显的操作
- jdbc学习:操作Oracle的CLOB和BLOB数据
- JDBC:数据库操作:处理大对象CLOB数据
- Mybatis之Oracle增删查改示例(含Date、Clob数据类型操作)
- JDBC存取ORACLE大型数据对象CLOB几种情况的示范类
- oracle里大数据保存至CLOB解决方法
- [Oracle]大数据类型的操作之CLOB
- java操作oracle的blob,clob数据
- Spring 让 LOB 数据操作变得简单易行,LOB 代表大对象数据,包括 BLOB 和 CLOB 两种类型
- HTML5数据存储---使用clear()方法清除localStorage保存对象的全部数据
- python从oracle读取数据并且保存在本地的小操作
- oracle 中的大对象数据类型blob、clob、nclob的意义以及区别
- 对Table的操作(赋值、动态新增行、删除行、保存table中多行数据对象
- 处理Clob数据(转)关于oracle中大对象处理的一些方法和实例
- java中操作Oracle clob数据出现的连接关闭问题
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- c++ 读写Oracle--Clob对象,注意数据编码长度
- oracle对大对象类型操作:blob,clob,nclob,bfile
- oracle中修改已有字段数据类型为clob的方法以及ssh框架中如何保存clob字段