oracle大字段处理方式--解决长度不够

<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.io.Writer" %>

<%

    //数据包准备
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
    }
    catch (java.lang.ClassNotFoundException e) {
        System.err.print(e);
    }
    //参数定义
    String url = "jdbc:oracle:thin:@192.168.9.96:1521:picc";
    String user = "eccc";
    String password = "eccc";

    String action = request.getParameter("action");
    int req;//SQL执行判断参数
    if (action == null) {
        out.println("");
        out.println(" ");
    }
    if (action.equals("0211")) {//判断是否合法请求


        String info_id = request.getParameter("info_id");

        String info_title = request.getParameter("info_title");

        // info_title=new String(info_title.getBytes("ISO8859_1"));


        String info_author = request.getParameter("info_author");
        //   info_author=new String(info_author.getBytes("ISO8859_1"));

        String info_source = request.getParameter("info_source");
        // info_source=new String(info_source.getBytes("ISO8859_1"));

        String info_type = request.getParameter("info_type");
        //  info_type=new String(info_type.getBytes("ISO8859_1"));

        String info_pubdate = request.getParameter("info_pubdate");

        String info_hidden = request.getParameter("info_hidden");
        //  info_hidden=new String(info_hidden.getBytes("ISO8859_1"));
%>

<%

    Connection conn = DriverManager.getConnection(url, user, password);

    Statement stmt = conn.createStatement();


    ResultSet check = stmt.executeQuery("select news_title from t_sm_info");
    int chk = 0;
    while (check.next()) {//检测新闻标题是否存在
        if (check.getString("news_title").equals(info_title))
            chk = 1;
    }
    if (chk == 1) {
        out.println("");
        out.println(" ");
    }
    if (chk != 1) {
        String addinfonew = "INSERT INTO T_SM_INFO ( NEWS_ID, NEWS_TYPE, NEWS_TITLE, NEWS_SOURCE, NEWS_DATE, NEWS_CONTENT, NEWS_AUTHOR ) VALUES('"
                + info_id
                + "','"
                + info_type
                + "','"
                + info_title
                + "','"
                + info_source
                + "',"
                + "sysdate"
                + ","
                + "empty_clob()"
                + ",'"
                + info_author + "')";

//         out.println("");
//            out.println(" ");

        req = stmt.executeUpdate(addinfonew);

        String sql_fordate = null;
        sql_fordate = "select news_content from t_sm_info where news_id='" + info_id + "' for update ";

        clobModify(sql_fordate, "NEWS_CONTENT", info_hidden);


        if (req == 1) {
            out.println("");
            out.println(" ");
        } else {
            out.println("");
            out.println(" ");
        }
    }


%>
<%
    } else {
        out.println("");
        out.println(" ");
    }

%>
<%!
    public void clobModify(String sql_forupdate, String lob_field, String clobdata) throws Exception {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        }
        catch (java.lang.ClassNotFoundException e) {
            System.err.print(e);
        }
        //参数定义
        String url = "jdbc:oracle:thin:@192.168.9.96:1521:picc";
        String user = "eccc";
        String password = "eccc";
        ResultSet rs;

        Connection conn = DriverManager.getConnection(url, user, password);

        Statement stmt;
        try {

            conn.setAutoCommit(false);

            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql_forupdate);
            if (rs.next()) {
                oracle.sql.CLOB clob = (oracle.sql.CLOB) (rs.getClob(lob_field));
                Writer outStream = clob.getCharacterOutputStream();

                char[] c = clobdata.toCharArray();
                outStream.write(c, 0, c.length);
                outStream.flush();
                outStream.close();
            }

            conn.commit();
            conn.close();
        }
        catch (Exception e) {
            System.out.println(e.toString());
        }

    }


%>

你可能感兴趣的:(oracle大字段处理方式--解决长度不够)