大家好 刚学Java没多久 有一个问题想请教一下各位 在线等 合用立即给分 谢谢问题就是 SQL Server数据库不能存储超过1万个汉字的字段
所以我想把输入的内容先写到.txt文件里
并根据时间命名
保存好后 再在数据库里保存文件所在的路径
读取的时候根据路径 显示.txt文件里的内容 不知道该怎么做 请大家指点 最好有具体的代码和注解 如果 关于如何存储大数据的不同办法 也尽请相告 不胜感激!!!!!
所以我想把输入的内容先写到.txt文件里
并根据时间命名
保存好后 再在数据库里保存文件所在的路径
读取的时候根据路径 显示.txt文件里的内容 不知道该怎么做 请大家指点 最好有具体的代码和注解 如果 关于如何存储大数据的不同办法 也尽请相告 不胜感激!!!!!
解决方案 »
- dom4j解析重复相同节点
- 我在rhel 5上刚装的rdesktop,连接时ERROR: Failed to open display:
- java_web找工作
- 启动tomcat,问题!
- 为什么不能读取路径下的文件信息?高分求助!!!
- 高分求助,关于图形显示的问题
- 在页面中插入表格
- Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用
- 在jsp页面怎么打开一个word文档?
- JSP页面的时间存到数据库只有年月日没有时分秒
- 你们现在的平均工资是多少啊 3年经验 java Web开发 5k是个什么标准。
- Java字符串分解,
如果对数据库,有blob和clob来处理大字段
CLOB字段主要存储文本信息,最长为4G.在J2EE程序中,比如网页的textarea中的字符信息比较长,Varchar2字段类型不能满足时,我们就得用CLOB数据类型
BLOB字段,二进制LOB,主要存储二进制数据,最长为4G,在J2EE程序中,一般类似于图片和文件的保存。
但是SQL Server数据库里没有blob和clob类型的字段啊....
text类型的字段 写入是没问题的 但是读取的时候 我试了集中方法 都没无效
请问改如何读取该字段
我用的是oracle数据库,里边有BLOB和CLOB,不过对于SQL SERVER也应该有类似的字段吧
就像AreamArgentateOfWing说得那个text一样
你用的是企业管理器创建表的吧,那你仔细看一下类型列里都有什么类型
请问text类型的字段该读取?或者有其他方法的也请指教
//获取页面上输入的数据
return str;
}
public void writeFile(String str){
BufferedWriter bw=null;
try{
java.text.SimpleDateFormat s = new java.text.SimpleDateFormat("yyyyMMddhhmm");
Date dt=new Date();
String strDate=s.format(dt);
System.out.println(strDate);
FileWriter wf=new FileWriter("D:/"+strDate+".txt");
bw = new BufferedWriter(wf);
bw.newLine();
bw.append(str);
bw.close();
}
catch(IOException e){
e.printStackTrace();
}
finally{
try{
bw.close();
}
catch(IOException e){}
}
}
//数据库就不用写了吧!!!!!
我是这么读取vachar类型字段的:
DBConnectBean ttt = new DBConnectBean();
DataTable tt=ttt.executeQuery("select * from s1 where s_id='"+s_id+"'");
s_content=dt.getFieldByName(0,"s_content");
.
.
.
然后 页面上用
<tr>
<td><%=s_content%></td>
</tr>
显示
我晚上回去试试 可以用的话 会给分的其他朋友 也请指教
DataTable、DBConnectBean这些类都是自己封装过的吧?
import java.sql.*;public class DBConnection {
String jdbcDriver = "DB.classForName";
String dbUserName = "DB.userName";
String dbPassword = "DB.passWord";
String dbUrl = "DB.dataBase"; /**
* 获得连接
*
* @param: 无
* @return: 返回类型:Connection,返回值描述:返回得到的连接
* @exception: Exception
*/ public Connection getConnection() throws Exception {
Connection conn = null;
Class.forName(jdbcDriver);
conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
return conn;
}
}
Query.javaimport java.sql.*;
import com.yhky.base.ExceptionDisponse;public class Query {
private ResultSet rs; // 查询记录集对象
private PreparedStatement ps; // 预编译 SQL 语句对象
private Connection con; // 连接数据库对象
private DBConnection dbc; public Query() {
} // 构造函数 /**
* 设置预编译SQL语句
*
* @param: 参数名:sqlstr,参数类型:String,参数描述:SQL语句.
* @return: 无
* @exception: 产生SQLException异常
*/ public void setpssql(String sqlstr) {
try {
this.ps = con.prepareStatement(sqlstr);
} catch (SQLException e) {
e.printStackTrace();
}
} /**
* 设置预编译SQL语句的参数
*
* @param: 参数名:i,参数类型:int,参数描述:对应参数的位置.<br>
* 参数名:psstr,参数类型:String,参数描述:参数值.
* @return: 无
* @exception: 产生SQLException异常
*/
public void setpsistr(int i, String psstr) {
try {
this.ps.setString(i, psstr);
} catch (Exception e) {
e.printStackTrace();
}
}
public void setpsistr(int i, double psstr) {
try {
this.ps.setDouble(i, psstr);
} catch (Exception e) {
e.printStackTrace();
}
}
public void setpsistr(int i, float psstr) {
try {
this.ps.setFloat(i, psstr);
} catch (Exception e) {
e.printStackTrace();
}
}
public void setpsistr(int i, int psstr) {
try {
this.ps.setInt(i, psstr);
} catch (Exception e) {
e.printStackTrace();
}
}
public void setpsistr(int i, Date psstr) {
try {
this.ps.setDate(i, psstr);
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 设置预编译SQL语句的参数
*
* @param: 无
* @return: 返回类型:ResultSet,返回值描述:查询结果
* @exception: 产生SQLException异常
*/
public ResultSet psQuery() {
try {
this.rs = this.ps.executeQuery();
} catch (SQLException ex) {
throw new ExceptionDisponse("Query", "psQuery", ex.getMessage());
} finally {
return this.rs;
}
} /**
* 插入查询,向数据库插入数据并返回插入查询的记录数
*
* @param: 无
* @return: 返回类型:int,返回值描述:插入查询的记录数
* @exception: 产生SQLException异常
*/
public int instQuery() {
int num = 0;
try {
num = this.ps.executeUpdate();
} catch (SQLException ex) {
throw new ExceptionDisponse("Query", "instQuery", ex.getMessage());
} finally {
return num;
}
} /**
* 修改查询,修改数据库数据并返回修改查询的记录数
*
* @param: 无
* @return: 返回类型:int,返回值描述:修改查询的记录数
* @exception: 产生SQLException异常
*/
public int updateQuery() {
int num = 0;
try {
num = this.ps.executeUpdate();
} catch (SQLException ex) {
throw new ExceptionDisponse("Query", "updateQuery", ex.getMessage());
} finally {
return num;
}
} /**
* 删除查询,修改数据库数据并返回删除查询的记录数
*
* @param: 无
* @return: 返回类型:int,返回值描述:删除查询的记录数
* @exception: 产生SQLException异常
*/
public int deleteQuery() {
int num = 0;
try {
num = this.ps.executeUpdate();
} catch (SQLException ex) {
throw new ExceptionDisponse("Query", "deleteQuery", ex.getMessage());
} finally {
return num;
}
} /**
* 建立数据库的连接,实例化 DBConneciton 对象
*
* @param: 无
* @return: 无
* @exception: 产生SQLException,ClassNotFoundException异常
*/
public void openDB() {
try {
this.dbc = new DBConnection(); // 池连接
this.con = this.dbc.getConnection();
} catch (Exception ex) {
ex.printStackTrace();
}
} /**
* 关闭记录集,连接对象,预编译语句对象
*
* @param: 无
* @return: 无
* @exception: 产生SQLException异常
*/
public void closeDB() {
try {
if (this.rs != null) {
this.rs.close();
}
if (this.ps != null) {
this.ps.close();
}
if (this.con != null) {
this.con.close();
}
this.con = null;
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}大概就是这样的。这是我05年写的,有很长时间没有看过了。不知道对你有没有用。
还想问一下 你在.jsp页面上是怎么调用的?
下面我说一下我对于oracle中大字段的处理思想吧
LOB数据不能象其它类型数据一样直接插入(INSERT)。插入前必须先插入一个空的LOB对象,CLOB类型的空对象为EMPTY_CLOB (),BLOB类型的空对象为EMPTY_BLOB()。之后通过SELECT命令查询得到先前插入的记录并锁定,继而将空对象修改为所要插入的LOB对象(主要是通过流的读写,即以数据库中的空对象创建一个流,然后把页面上输入的数据放入这个流中,然后把流关闭,从而使页面上输入的数据放入数据库)。
我们在保存的时候,CLOB字段会把上面textarea中的文本按原来的格式一行一行(包括空格)都保存到CLOB字段中,读取的时候我们只要按照原来格式读起出来就行了
今天上午也没有什么事,要不等会我把oracle中大字段的总结一下,放到我得blog中,你可以去看一下具体的实现方式
ArrayList arr = new ArrayList();
query.openDB();
query.setpssql("select * from s1 where s_id=? ");
query.setpsistr(1, s_id);
ResultSet rs = this.query.psQuery();
try {
while (rs.next()) {
arr.add(rs.getString('s_content '));
}
} catch (Exception e) {
new ExceptionDisponse(e);
}
query.closeDB();
public String getFile(String title) {
BufferedReader br;
StringBuffer sb = new StringBuffer();
try {
br = new BufferedReader(new FileReader(title));
String content = br.readLine();
while (content != null) {
sb.append(content + "\n");
content = br.readLine();
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}