熟悉 jacob 的朋友请进来看看! 这是我处理word文档的方法,早就放到csdn文档里面了自己去看看吧,希望对你有些帮助http://dev.csdn.net/develop/article/25/25116.shtm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我己经能成功存到数据库中,数据库:mssqlserver字段类型:image读的方法正在研究之中,请各位高手指点一下,先谢谢了!写的代码在下面,大家共同进步,特别感谢楼上的兄弟,就是sqlserver的具体怎么写不会!--------------------------------------------------<%@ page language="java"%> <%@ page contentType="text/html;charset=gb2312" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*"%> <%@ page import="java.text.*"%> <%@ page import="java.io.*"%> <% try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; //test为你的数据库的 String user="sa"; //用户名 String password=""; //密码 Connection conn= DriverManager.getConnection(url,user,password); out.write("连接数据库成功!"); out.write("运行到这了-1!"); //插入数据库 String sql="insert into test_img values (?,?,?)"; //获取传值ID out.write("运行到这了-1!"); String id=request.getParameter("id"); //获取image的路径 out.write("运行到这了-2!"); String kk=request.getParameter("image"); //转换成file格式 File filename=new File(kk); out.write("运行到这了-3!"); //将文件的长度读出,并转换成Long型 long l1=filename.length(); int l2=(int)l1; //以流的格式赋值 FileInputStream fis=new FileInputStream(filename); PreparedStatement ps =conn.prepareStatement(sql); ps.setString(1,id); ps.setString(2,filename.getName()); ps.setBinaryStream(3,fis,l2); ps.executeUpdate(); ps.close(); } catch(Exception e){ out.write(e.getMessage()); } finally{ }%> 问题己经搞定!下面的代码是读出word文档从数据库,希望大家共享!----------------------<%@ page language="java"%> <%@ page contentType="text/html;charset=gb2312" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*"%> <%@ page import="java.text.*"%> <%@ page import="java.io.*"%> <% try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; //test为你的数据库的 String user="sa"; //用户名 String password=""; //密码 Connection conn= DriverManager.getConnection(url,user,password); out.write("连接数据库成功!"); //插入数据库 String sql="select * from test_img where id=123"; //执行sql语句 PreparedStatement ps =conn.prepareStatement(sql); ps.execute(); System.out.println("己经能正确执行查找了"); ResultSet rs=ps.getResultSet(); //记住一定要移动游标! rs.next(); String id=rs.getString("id"); String filename=rs.getString("name"); filename="f:\\"+filename; out.write(id); out.write(filename); InputStream is=rs.getBinaryStream("image"); byte[] buffer = new byte[1000000]; is.read(buffer); is.close(); FileOutputStream fos = new FileOutputStream(filename); fos.write(buffer); fos.close(); ps.close(); out.write("生成word文档成功!"); } catch(Exception e){ out.write(e.getMessage()); } finally{ }%> struts中的间接传值。 产品模式下的weblogic在更新class后,有什么办法手动reload servlet而不用重启或重部署??? 对bean进行setProperty却不执行,为什么? spring AOP中如何给通知传递参数 jpetstore 安装问题有的网页访问异常 大量数据提交能用Struts吗 新人问题,大家帮忙 实体bean的回调函数问题 用EJB+JSP+SERVLET進行開發,能否使用RMI-IIOP協議呢? hibernate的问题 对象引用的问题,请问怎么解决? 向各位求救了!关于XML文档存储到关系数据库的问题。
数据库:mssqlserver
字段类型:image
读的方法正在研究之中,请各位高手指点一下,先谢谢了!
写的代码在下面,大家共同进步,特别感谢楼上的兄弟,就是sqlserver的具体怎么写不会!
--------------------------------------------------
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%> <% try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
//test为你的数据库的
String user="sa"; //用户名
String password=""; //密码
Connection conn= DriverManager.getConnection(url,user,password);
out.write("连接数据库成功!");
out.write("运行到这了-1!");
//插入数据库
String sql="insert into test_img values (?,?,?)";
//获取传值ID
out.write("运行到这了-1!");
String id=request.getParameter("id");
//获取image的路径
out.write("运行到这了-2!");
String kk=request.getParameter("image");
//转换成file格式
File filename=new File(kk);
out.write("运行到这了-3!");
//将文件的长度读出,并转换成Long型
long l1=filename.length();
int l2=(int)l1;
//以流的格式赋值
FileInputStream fis=new FileInputStream(filename);
PreparedStatement ps =conn.prepareStatement(sql);
ps.setString(1,id);
ps.setString(2,filename.getName());
ps.setBinaryStream(3,fis,l2);
ps.executeUpdate();
ps.close();
}
catch(Exception e){
out.write(e.getMessage());
}
finally{
}
%>
下面的代码是读出word文档从数据库,希望大家共享!
----------------------
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%> <% try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
//test为你的数据库的
String user="sa"; //用户名
String password=""; //密码
Connection conn= DriverManager.getConnection(url,user,password);
out.write("连接数据库成功!");
//插入数据库
String sql="select * from test_img where id=123";
//执行sql语句
PreparedStatement ps =conn.prepareStatement(sql);
ps.execute();
System.out.println("己经能正确执行查找了");
ResultSet rs=ps.getResultSet();
//记住一定要移动游标!
rs.next();
String id=rs.getString("id");
String filename=rs.getString("name");
filename="f:\\"+filename;
out.write(id);
out.write(filename);
InputStream is=rs.getBinaryStream("image");
byte[] buffer = new byte[1000000];
is.read(buffer);
is.close();
FileOutputStream fos = new FileOutputStream(filename);
fos.write(buffer);
fos.close();
ps.close();
out.write("生成word文档成功!");
}
catch(Exception e){
out.write(e.getMessage());
}
finally{
}
%>