我是JSP新手,简单的JSP编写就差不多了。但是现在我很头疼,就是oracle数据库在提交2000字以上的文章时出错了。"内容“我用的是龙的类型。
提交一个正常使用情况下少于2000字的代码:
& lt%@包含文件= & quotInc/conn . JSP & quot;% & gt
& lt% if((String)session . get attribute(& quot;adminlogin & quot)= = = & quot;是的& quot){ % & gt
& lt%
request . setcharacterencoding(& quot;GB2312 & quot);
//文章名称
string art _ name = request . getparameter(& quot;art _ name & quot);
//文章列ID
string art _ class _ id = request . getparameter(& quot;art _ class _ id & quot);
//屋顶是否固定
string art _ top = request . getparameter(& quot;art _ top & quot);
if(art _ top = = null | | art _ top = = & quot;"){
art _ top = & quot0 & gt;;
}
//文章的内容
string content = request . getparameter(& quot;conten & quot);
字符串sql = & quot插入到szgs_art(art_id,art_class_id,art_name,art_conts,art_top,art_ow)值(art_id.nextval,' & quot+art _ class _ id+& quot;',' & quot+art _ name+& quot;',' & quot+content+& quot;',' & quot+art _ top+& quot;',1)& quot;;
stmt . execute query(SQL);
out . print(& quot;& lt脚本语言= ' javascript ' & gt");
out . print(& quot;Alert('文章添加成功!');");
out . print(& quot;location . href = ' gsdt _ add . JSP ';");
out . print(& quot;& lt/script & gt;");
stmt . close();
conn . close();
% & gt
& lt% } else { % & gt& lt% } % & gt
后来在网上找了很久也没有好的解决办法。我发现了一个我不会用的段落:
& lt%
DriverManager.registerDriver(新Oracle . JDBC . driver . Oracle driver());
connection conn = driver manager . get connection(& quot;Java:Oracle:thin:@ SRV:1521:SRV & quot;,& quotyp & quot,& quotyp & quot);
字符串sql = & quot插入到speedfaw.news值(?,?)& quot;
prepared statement pstmt = conn . prepare statement(SQL);
string title = request . getparameter(& quot;标题& quot);
string content = request . getparameter(& quot;内容& quot);
String temp =新字符串(content . getbytes(& quot;iso 8859-1 & quot;),& quotGBK & quot;);
byte[]pic = temp . getbytes(& quot;GBK & quot;);
bytearrayiputstream baisss = new bytearrayiputstream(pic);
InputStreamReader Bais = new InputStreamReader(baiss,& quotGBK & quot;);
pstmt.setString(1,标题);
pstmt.setCharacterStream(2,bais,pic . length);
pstmt . execute();
pstmt . close();
conn . close();
% & gt
最后,可以成功添加新数据的代码是:
我也用过LOB类型,但还是不会用。
最后,我使用了LONG,
添加文章:
DriverManager.registerDriver(新Oracle . JDBC . driver . Oracle driver());
connection conn = driver manager . get connection(& quot;Java:Oracle:thin:@ SRV:1521:SRV & quot;,& quotyp & quot,& quotyp & quot);
字符串sql = & quot插入到speedfaw.news值(?,?)& quot;
prepared statement pstmt = conn . prepare statement(SQL);
string title = request . getparameter(& quot;标题& quot);
string content = request . getparameter(& quot;内容& quot);
String temp =新字符串(content . getbytes(& quot;iso 8859-1 & quot;),& quotGBK & quot;);
byte[]pic = temp . getbytes(& quot;GBK & quot;);
bytearrayiputstream baisss = new bytearrayiputstream(pic);
InputStreamReader Bais = new InputStreamReader(baiss,& quotGBK & quot;);
pstmt.setString(1,标题);
pstmt.setCharacterStream(2,bais,pic . length);
pstmt . execute();
pstmt . close();
conn . close();
% & gt
使用成功。
关键词:oracle,长数据
优侠库网站每天提供最新最热门的安卓手机软件、游戏下载、分享热门手游资讯攻略教程、手机软件教程步骤,专注安卓手机游戏软件下载。本文链接:http://www.123down.cn/gonglue/227400.html