時間:2015/6/28來源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評論(0)
我是JSP新手,簡單的JSP寫也差不多了。但是現(xiàn)在碰到一個頭痛的問題,就是在提交大于2000字的文章時,oracle數(shù)據(jù)庫就出錯了。"文章內(nèi)容" 我用的是LONG的類型。
提交小于2000字的使用正常的代碼:
<%@ include file="inc/conn.jsp"%>
<%if ((String) session.getAttribute("adminlogin")=="yes"){%>
<%
request.setcharacterEncoding("GB2312");
//文章名稱
String art_name = request.getParameter("art_name");
//文章欄目ID
String art_class_id = request.getParameter("art_class_id");
//是否固頂
String art_top = request.getParameter("art_top");
if(art_top==null||art_top==""){
art_top = "0";
}
//文章內(nèi)容
String content = request.getParameter("conten");
String sql="insert into szgs_art(art_id,art_class_id,art_name,art_conts,art_top,art_ow) values (art_id.nextval,'"+art_class_id+"','"+art_name+"','"+content+"','"+art_top+"',1)";
stmt.executeQuery(sql);
out.print("<script language='javascript'>");
out.print("alert('文章增加成功!');");
out.print("location.href='gsdt_add.jsp';");
out.print("</script>");
stmt.close();
conn.close();
%>
<%}else{%><%}%>
后來在網(wǎng)上查了半天也沒有好的解決辦法。倒是找到了一段我不會用的:
<%
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("java:oracle:thin:@srv:1521:srv","yp","yp");
String sql= "INSERT INTO speedfaw.news VALUES(?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
String title=request.getParameter("title");
String content=request.getParameter("content");
String temp = new String(content.getBytes("ISO8859-1"),"GBK");
byte[] pic = temp.getBytes("GBK");
ByteArrayInputStream baisss = new ByteArrayInputStream(pic);
InputStreamReader bais = new InputStreamReader(baisss,"GBK");
pstmt.setString(1,title);
pstmt.setCharacterStream(2,bais,pic.length);
pstmt.execute();
pstmt.close();
conn.close();
%>
最后能成功添加新數(shù)據(jù)的代碼為:
LOB類型我也用了還是用不起來
最后還是用LONG了,
增加文章時用:<%
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("java:oracle:thin:@srv:1521:srv","yp","yp");
String sql= "INSERT INTO speedfaw.news VALUES(?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
String title=request.getParameter("title");
String content=request.getParameter("content");
String temp = new String(content.getBytes("ISO8859-1"),"GBK");
byte[] pic = temp.getBytes("GBK");
ByteArrayInputStream baisss = new ByteArrayInputStream(pic);
InputStreamReader bais = new InputStreamReader(baisss,"GBK");
pstmt.setString(1,title);
pstmt.setCharacterStream(2,bais,pic.length);
pstmt.execute();
pstmt.close();
conn.close();
%>
使用成功
關(guān)鍵詞標(biāo)簽:oracle,long類型數(shù)據(jù)
相關(guān)閱讀
熱門文章 Oracle中使用alter table來增加,刪除,修改列oracle中使用SQL語句修改字段類型-oracle修使用低權(quán)限Oracle數(shù)據(jù)庫賬戶得到管理員權(quán)限Oracle對user的訪問控制
人氣排行 ORACLE SQL 判斷字符串是否為數(shù)字的語句Oracle中使用alter table來增加,刪除,修改列的語法ORACLE和SQL語法區(qū)別歸納(1)oracle grant 授權(quán)語句如何加速Oracle大批量數(shù)據(jù)處理Oracle刪除表的幾種方法ORACLE修改IP地址后如何能夠使用Oracle 10g創(chuàng)建表空間和用戶并指定權(quán)限