我是JSP新手,简单的JSP写也差不多了。但是现在碰到一个头痛的问题,就是在提交大于2000字的文章时,oracle数据库就出错了。"文章内容" 我用的是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";
}
//文章内容
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{%><%}%>
后来在网上查了半天也没有好的解决办法。倒是找到了一段我不会用的:
<%
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();
%>
最后能成功添加新数据的代码为:
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();
%>
使用成功
关键词标签:oracle,long类型数据
相关阅读
热门文章 Oracle中使用alter table来增加,删除,修改列oracle中使用SQL语句修改字段类型-oracle修使用低权限Oracle数据库账户得到管理员权限Oracle对user的访问控制
人气排行 ORACLE SQL 判断字符串是否为数字的语句Oracle中使用alter table来增加,删除,修改列的语法ORACLE和SQL语法区别归纳(1)oracle grant 授权语句如何加速Oracle大批量数据处理Oracle删除表的几种方法ORACLE修改IP地址后如何能够使用Oracle 10g创建表空间和用户并指定权限
查看所有0条评论>>