数据表:PersonnelPhoto1 字段:photoimage 数据类型image
怎样使用Java读取该字段的值(存取的都是bmp位图)。请各位专家帮忙支招!最好有代码!
怎样使用Java读取该字段的值(存取的都是bmp位图)。请各位专家帮忙支招!最好有代码!
解决方案 »
- ssh各自的角色
- 界面问题
- 为啥Oracle里的Date类型的时间,读不出时分秒呀
- url重写
- jbuilder2006+weblogic8 发布应用程序是jbuilder报错 Unrecognized option or flag, -sourcerootforupload
- 面试中遇到的一个问题,关于jsp中值传递的!哪位教教我!!!
- 请帮忙看一下,我这样配置tomcat5.5为什么不对?
- 反编译出来的JAVA文件里面怎么有这样子的东东~~~~~急~~
- 请问哪位有Jive或Jive_JDon的比较完整的UML图提供,高分答谢!
- struts例子研究,情指教
- JSP 中使用 synchronized 出现不解现象
- javaBean的问题,高手请进
import java.sql.*;
import java.io.*;
import java.lang.*;
import java.awt.*;
public class fileopen{
public static void main(String args[]){
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:test","sa","");
Statement stmt=con.createStatement();
ResultSet rs;
String sql="select photoimage from PersonnelPhoto1 where xx=xx";
rs=stmt.executeQuery(sql);
while(rs.next())
{
InputStream image = rs.getBinaryStream("photoimage");//photoimg为image类型
String len=image.toString();
long length=len.length();
int ch = 0;
byte[] buffer = new byte[(int)length/7];
File file = new File("c:\\test.jpg");//将数据写入文件
if(!file.exists())
{
file.createNewFile();
}
FileOutputStream newFile = new FileOutputStream(file,true); boolean go = true;
while(go)
{
while((ch = image.read(buffer))!=-1)
{
newFile.write(buffer);
}
go=false;
}
}
}
catch(Exception e){System.out.print(e);}
}}
OutputStream out;
out = new FileOutputStream(file);
/** //or for javax.servlet.http.HttpServletResponse
* response.setContentType("image/bmp");
* out = response;
*/
rs = stmt.executeQuery(sql);
while (rs.next())
{
InputStream in = rs.getBinaryStream("photoimage");
byte[] buffer = new byte[256]; while (in.read(buffer) != -1)
{
out.write(buffer);
}
in.close();
}
out.close();[code]