Solution of BLOB type storage large text problem in oracle+jsp

Source: Internet
Author: User
Tags commit sort stmt

Oracle storage of large text has been a thorny issue.

First, the storage database:

<% @page contenttype= "text/html; charset=gb2312 "language=" java "import=" java.sql.* "errorpage=" "%>"
<%
Defining variables
Java.sql.Connection Conn; Database Connection objects
String SQL;
Long ID;
ResultSet rs;
Statement Stmt,stmt1;java.sql.drivermanager.registerdriver (New Oracle.jdbc.driver.OracleDriver ()); Load JDBC Driver
conn = Java.sql.DriverManager.getConnection ("Jdbc:oracle:thin:@192.168.1.2:1521:lqxm", "Lqxm", "LQXM"); Connecting to a database
Request.setcharacterencoding ("GBK");
String title = Request.getparameter ("title");
String content = request.getparameter ("content");
String sort = request.getparameter ("sort");
String type = Request.getparameter ("type");
String RQ = Request.getparameter ("RQ");
String qy = Request.getparameter ("qy");
Inserting data, where a null value is inserted in the BLOB field
Sql= "INSERT into T_FLFG (xlh,title,content,rq,sort,type,qy)";
sql=sql+ "Values" (flfg_seq. Nextval, ' + title + ', Empty_clob (), ' "+ RQ +" ', ' "+ sort +" ', ' "+ Type +" ', ' "+ qy +" ";
Stmt=conn.createstatement ();
Stmt.executeupdate (SQL);
Conn.commit ();
Conn.setautocommit (FALSE);
stmt = Conn.createstatement (resultset.type_scroll_sens99vive,resultset.concur_updatable);
Get the ID you just inserted
Sql= "select Max (XLH) as XLH from T_FLFG";
Rs=stmt.executequery (SQL);
if (Rs.next ()) {
Id=rs.getint ("Xlh");
}
Rs.close ();
sql = "Select content from T_FLFG where xlh=" +id+ "for Update";
rs = stmt.executequery (SQL);
if (Rs.next ()) {
Oracle.sql.CLOB CLOB = (Oracle.sql.CLOB) rs.getclob (1);
Clob.putstring (1, content);
sql = "Update T_FLFG set content=?" where xlh= "+ ID +" "; To update the big text in, hehe
PreparedStatement pstmt = conn.preparestatement (sql);
Pstmt.setclob (1, CLOB);
Pstmt.executeupdate ();
}
Conn.commit ();
Stmt.close ();
Conn.close ();
%>

Second, retrieve the display data:

<%
ResultSet rs = flfgSave.searchOneInfo(request.getParameter("xlh")); //查询数据库获取记录集
rs.next();
int y;
String content = "";
oracle.sql.CLOB clob1;
char ac[] = new char[299];
String title = rs.getString("title");
clob1 = (oracle.sql.CLOB)rs.getObject("content");
Reader reader = clob1.getCharacterStream();
while((y = reader.read(ac, 0, 299)) != -1)
content += new String(ac, 0, y); //这就是取出来的大文本
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.