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); //这就是取出来的大文本
%>