java可以操作word吗? poi主要是excel,好象没有关于word的,据说正在开发中! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 POI可以只是支持交差而已 我也是正要在java中操作word,下载了poi,没有支持word的功能 http://expert.csdn.net/Expert/topic/2361/2361145.xml?temp=.4011499 我做的是把表格导入WORD并打印,图片没是试过。 可以,把word实体插入到oracle的blob中,其他的数据库的大字段中也是可以的给你一个例子首先建一个表测试一下吧create table javatest(name varchar(10),content BLOB);package yourpackage;import java.sql.*;import java.io.*;import oracle.sql.*;import beans.common.*;public class insertBlobBean { public static void main(String args[]){ try{ // DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); connectionMgr connectMgr=new connectionMgr(); Connection conn=null; //链接数据库 try{ conn=connectMgr.getConnection(); }catch(Exception e){ System.out.println(e.toString()); } conn.setAutoCommit(false); BLOB blob=null; //首先往BLOB中插入一个空的blob PreparedStatement pstmt = conn.prepareStatement("insert into javatest(name,content) values(?,empty_blob())"); pstmt.setString(1,"wyx"); pstmt.executeUpdate(); pstmt.close(); //然后取出这个空的blob字段 pstmt = conn.prepareStatement("select content from javatest where name= ? for update "); pstmt.setString(1,"wyx"); ResultSet rset = pstmt.executeQuery(); if (rset.next()) blob = (BLOB)rset.getBlob(1); String fileName = "f:\\1111.doc"; File f = new File(fileName); FileInputStream fin = new FileInputStream(f); System.out.println("file size = " + fin.available()); //更新这个字段 pstmt = conn.prepareStatement("update javatest set content=? where name=?"); //往blob里面写入文件 OutputStream out = blob.getBinaryOutputStream(); int count = -1, total = 0; byte[] data = new byte[(int)fin.available()]; fin.read(data); out.write(data); /*byte[] data = new byte[blob.getBufferSize()]; 另一种实现方法,节省内存 while ((count = fin.read(data)) != -1) { total += count; out.write(data, 0, count); } */ out.flush(); fin.close(); out.close(); pstmt.setBlob(1,blob); System.out.println(blob.length()); pstmt.setString(2,"wyx"); pstmt.executeUpdate(); pstmt.close(); conn.commit(); conn.close(); }catch(SQLException e){ System.err.println(e.getMessage()+e.toString()); }catch (IOException e) { System.err.println(e.getMessage()+e.toString()); } }} 关于word读取显示的看看http://www.csdn.net/Develop/read_article.asp?id=25116或许对你有一些帮助 我也正在考虑这个问题,不过现在的这些工具好像都是直接把整篇word文档作为一个大字段存放到数据库中,不能以更小的粒度抽取出word中的内容分别放到数据库中. struts2 结果集传参 Hibernate 执行操作插入操作重复提交 多选按钮怎么操作? hibernate 3.2 添加完数据 但是查询不出来 JSP分页问题...请高手指点 【我要连局域网的sql server2K 我的机器需要装sql server2K或者什么组件吗?】 如何实现这样的WEB访问?求思路和基本方法。 页面间参数传递问题?? jsp页面一打印就退纸,急!!! 高分求助:怎样修改xml文件的一个元素的属性的值? 请问如何在web网页上嵌入word文档,并可以在线编辑,并可以存入服务器 小弟不知选用什么工具配开发环境以及如何配置
name varchar(10),
content BLOB);
package yourpackage;
import java.sql.*;
import java.io.*;
import oracle.sql.*;
import beans.common.*;public class insertBlobBean {
public static void main(String args[]){
try{
// DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
connectionMgr connectMgr=new connectionMgr();
Connection conn=null;
//链接数据库
try{
conn=connectMgr.getConnection();
}catch(Exception e){
System.out.println(e.toString());
}
conn.setAutoCommit(false);
BLOB blob=null;
//首先往BLOB中插入一个空的blob
PreparedStatement pstmt = conn.prepareStatement("insert into javatest(name,content) values(?,empty_blob())"); pstmt.setString(1,"wyx");
pstmt.executeUpdate();
pstmt.close();
//然后取出这个空的blob字段
pstmt = conn.prepareStatement("select content from javatest where name= ? for update ");
pstmt.setString(1,"wyx"); ResultSet rset = pstmt.executeQuery();
if (rset.next())
blob = (BLOB)rset.getBlob(1);
String fileName = "f:\\1111.doc";
File f = new File(fileName);
FileInputStream fin = new FileInputStream(f);
System.out.println("file size = " + fin.available());
//更新这个字段
pstmt = conn.prepareStatement("update javatest set content=? where name=?");
//往blob里面写入文件
OutputStream out = blob.getBinaryOutputStream();
int count = -1, total = 0;
byte[] data = new byte[(int)fin.available()];
fin.read(data);
out.write(data);
/*byte[] data = new byte[blob.getBufferSize()];
另一种实现方法,节省内存
while ((count = fin.read(data)) != -1) {
total += count; out.write(data, 0, count); }
*/
out.flush();
fin.close();
out.close(); pstmt.setBlob(1,blob);
System.out.println(blob.length());
pstmt.setString(2,"wyx");
pstmt.executeUpdate();
pstmt.close();
conn.commit();
conn.close();
}catch(SQLException e){
System.err.println(e.getMessage()+e.toString());
}catch (IOException e) {
System.err.println(e.getMessage()+e.toString()); }
}
}
http://www.csdn.net/Develop/read_article.asp?id=25116或许对你有一些帮助
存放到数据库中,不能以更小的粒度抽取出word中的内容分别放到数据库中.