String转Oracle中的CLOB

项目中遇到的将String转CLOB
/**

     * 将String转换为CLOB
     * @author ZhaoHr
     * @param sort
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    @SuppressWarnings("unused")
    public int insertSortWithStr2CLOB(Sort sort) throws ClassNotFoundException, SQLException {
        // TODO Auto-generated method stub
        DriverManager.registerDriver(new OracleDriver());
        String url = "jdbc:oracle:thin:@localhost:1521:orcl";
        String user = "SHOPGUIDE";
        String pwd = "SHOPGUIDE";
        String text = sort.getInfo();
        Connection conn = DriverManager.getConnection(url, user, pwd);// 得到连接对象
        String sql = "INSERT INTO WEBSITE_SORT (ID, NAME,SORT_LEVEL,PARENT_SORT,ARRANGE ,ISSHOW,PIC1,INFO,REMARK,COMPANY_ID,UPDATE_DATE,UPDATE_USER) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement stmt = conn.prepareStatement(sql);// 加载SQL语句
        Reader clobReader = new StringReader(text); // 将 text转成流形式
        stmt.setInt(1, sortSequence.nextIntValue());
        stmt.setString(2, sort.getName());
        stmt.setString(3, sort.getSortLevel());
        stmt.setInt(4, sort.getParentSort());
        stmt.setString(5, sort.getArrange());
        stmt.setString(6, sort.getIsShow());
        stmt.setInt(7, sort.getPic1());
        stmt.setCharacterStream(8, clobReader, sort.getInfo().length());// 替换sql语句中的?将String转CLOB
        stmt.setString(9, sort.getRemark());
        stmt.setString(10, sort.getCompanyId());
        stmt.setDate(11, new java.sql.Date(sort.getUpdateDate().getTime()));
        stmt.setString(12, sort.getUpdateUser());
        int num = stmt.executeUpdate();// 执行SQL
        stmt.close();
        conn.close();
        return num;
    }

你可能感兴趣的:(String转Oracle中的CLOB)