Oracle JSP Big Big Text Problem Solution Oracle Storage Big Text has always been a tricky problem. First, save the database: <% @ page contenttype = "text / html; charset = GB2312" Language = "java" import = "java.sql. *" ErrorPage = ""%> <% // Define variable java.sql. Connection conn; // Database connection object string sql; long id; resultset rs; statement stmt, stmt1;
Java.sql.driverManager.RegisterDriver (new oracle.jdbc.driver.Orcledriver ()); // loaded JDBC driver conn = java.sql.drivermanager.getConnection ("JDBC: Oracle: Thin: @ 192.168.1.2: 1521: LQXM "," LQXM "," LQXM "); // Connect the 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 = request.getParameter ("qy"); // Insert data, inserts null value sql = "Insert in the blob field 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_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // just inserted acquired ID sql = "select max (xlh) as xlh from t_flfg"; rs = stmt.executeQuery (sql ); If (rs.next ()) {id = rs.getinT ("xlh");
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 ""; // update the big text into, huh, " (SQL); PSTMT.SETCLOB (1, Clob); PSTMT.ExecuteUpdate ();} conn.commit (); stmt.close (); conn.close ();%> Second, retrieval display data: <% resultT RS = flgsave.searchoneInfo ("xlh")); // Query the database to get record set 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); // This is the big text that is taken out>