- <%@ page import="java.io.*"%>
- <%@ page import="oracle.sql.CLOB"%>
- <%
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
- int imgId=23;
- String url="jdbc:oracle:thin:@localhost:1521:ORCL";
- Connection conn=DriverManager.getConnection(url,"system","oracle");
- Statement st = conn.createStatement();
- st.executeQuery("insert into hr.psn values("+ imgId +",'wenzhixing',EMPTY_CLOB())");
- ResultSet rs = st.executeQuery("select filestr from hr.psn where id="+ imgId +" for update");
- conn.setAutoCommit(false);
- if (rs.next())
- {
- /* 取出此CLOB对象 */
- oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("filestr");
- /* 向CLOB对象中写入数据 */
- Writer outStream = clob.getCharacterOutputStream();
- // 这里用一个文件模拟输入流
- FileReader in = new FileReader(new File("f://2.mht"));///本地的文件位置
- char[] b = new char[clob.getBufferSize()];
- int len = -1;
- while ((len = in.read(b)) != -1)
- {
- outStream.write(b, 0, len);
- }
- in.close();
- outStream.close();
- }
- conn.commit();
- rs.close();
- st.close();
- conn.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- %>
JSP Oralcle CLOB 文件保存
最新推荐文章于 2023-02-13 14:48:35 发布