QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1694|回复: 6

初学JSP:请教如何将大量文本带格式存入数据库??

[复制链接]
发表于 2004-5-30 15:23:39 | 显示全部楼层 |阅读模式
我在学用jsp写一个留言板,写到保存留言的部分,用DW中的Form:TextField 控件输入留言,然后post 到一个处理上传的jsp文件。

先用request.getParamter() 取得post过来的变量Content,再定义sql
String Update=\"UPDATE Table SET Content ='\"+ Content + \"' WHERE ID =\"+ID;

调用javaBean :UploadBean.executeUpdate("Update");

试运行,结果发现输入的文本少时工作正常,但输入时加了换行以后,输出的留言没有换行,如果paste一篇比较长的文章进去,就好像根本就不更新数据库了。请问这是什么原因?是不是String变量的长度限制??

多谢!
发表于 2004-5-30 17:25:48 | 显示全部楼层
输出时将'\n'替换为"\n<br>"就有换行了。
不能更新与具体的数据库有关,保存大文本时建议使用PreparedStatement
回复

使用道具 举报

发表于 2004-5-30 17:29:30 | 显示全部楼层
PreparedStatement

是什么东东
回复

使用道具 举报

 楼主| 发表于 2004-5-30 18:58:51 | 显示全部楼层
谢谢minsj, 请问那个PreparedStatement 是什么东东,怎么个用法?
回复

使用道具 举报

 楼主| 发表于 2004-5-30 19:01:09 | 显示全部楼层
btw 我用的是access 2000的数据库
回复

使用道具 举报

发表于 2004-5-31 10:04:36 | 显示全部楼层
参考:j2sdk-1_4_2-doc,在 java.sun.com 有下载

An object that represents a precompiled SQL statement.

A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note: The setter methods (setShort, setString, and so on) for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type INTEGER, then the method setInt should be used.

If arbitrary parameter type conversions are required, the method setObject should be used with a target SQL type.

In the following example of setting a parameter, con represents an active connection:
[code:1]
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)
[/code:1]
回复

使用道具 举报

 楼主| 发表于 2004-5-31 12:18:39 | 显示全部楼层
谢谢,我在看。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-13 20:21 , Processed in 0.051877 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表