百分求解~!!十万火急 先连接数据库,用io包将文件读成文件流,将文件流存进数据库(我以前用的是SQL SERVER)就行了,以前就这么做的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.sql.*;public class GetTif{ String Url="jdbc:odbc:Test",JdbcUser="system",JdbcPwd="manager"; public static BufferedReader getBufferedReader(String fName) { try{ FileReader fR=new FileReader(fName); if(fR==null)return null; return new BufferedReader(fR); }catch(Exception ex) {ex.printStackTrace();return null;} } //存储过度文件 private void saveFile(String DocID,InputStream inole) { try{ byte[] OleByte = getOle(inole); FileOutputStream f = new FileOutputStream("d:\\documents\\GetOLE\\"+DocID+".Tif"); f.write(OleByte); } catch(Exception e) { e.printStackTrace(); } } //读二进制数据 private static byte[] getOle(InputStream s) { byte[] buffer = new byte[0]; byte[] chunk = new byte[4096]; int count; try{ while((count = s.read(chunk))>=0) { byte[] t = new byte[buffer.length+count]; System.arraycopy(buffer,0,t,0,buffer.length); System.arraycopy(chunk,0,t,buffer.length,count); buffer=t; } }catch(Exception e){} return buffer; } //初始化配置信息 public GetTif(BufferedReader brin) { if(brin==null)return; try{ this.Url=brin.readLine().trim(); this.JdbcUser = brin.readLine().trim(); this.JdbcPwd = brin.readLine().trim(); brin.close(); }catch(IOException ex) {System.err.println("FileIOError:"+ex);} } //读数据库 private void readDB() { //注册数据库驱动程序 try{ DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver()); } catch(Exception e) {System.err.println("注册数据库驱动程序错误:" + e);} //从数据库读OLE或附件 try{ Connection con = DriverManager.getConnection(Url,JdbcUser,JdbcPwd); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM image_files"); java.math.BigDecimal DocNo; InputStream inTif; while(rs.next()){ try{ DocNo = rs.getBigDecimal("NO",0); inTif = rs.getBinaryStream("TIF"); saveFile(DocNo.toString(),inTif); System.out.println("存储过度Tif文件:"+DocNo.toString()); } catch(Exception e) {System.err.println("存储过度文件错误:" + e);} } st.close(); con.close(); } catch(Exception e) {System.err.println("数据库查询错误:" + e);} } public static void main(String args[]) { GetTif gt = new GetTif(getBufferedReader("d:\\documents\\GetOLE\\class\\odbc.ini")); gt.readDB(); }} odbc.ini的内容jdbc:odbc:testOletesttest ajax 局部定时刷新? 这是什么报错提示啊???大虾们,急急急!!! struts2初学 java项目发布 后的操作问题 新手报到,忘给点指导 请问大家jb2005有汉化版吗? 请问哪个中文网站可以下weblogic,最好不要适用版的! 一个jar的容易问题,当然我不觉得容易,我查不到答案 经典问题:EntityBean-BMP 环境设置错误。 struts2 2.5.12 struts.xml action标签class找不到 用jbuilder建立web (jsp)应用程序的步骤是什么???? 各位,请推荐几本学习Java的必要、经典之作!
import java.sql.*;public class GetTif
{
String Url="jdbc:odbc:Test",JdbcUser="system",JdbcPwd="manager"; public static BufferedReader getBufferedReader(String fName)
{
try{
FileReader fR=new FileReader(fName);
if(fR==null)return null;
return new BufferedReader(fR);
}catch(Exception ex)
{ex.printStackTrace();return null;}
} //存储过度文件
private void saveFile(String DocID,InputStream inole)
{
try{
byte[] OleByte = getOle(inole);
FileOutputStream f = new FileOutputStream("d:\\documents\\GetOLE\\"+DocID+".Tif");
f.write(OleByte);
} catch(Exception e) {
e.printStackTrace();
}
} //读二进制数据
private static byte[] getOle(InputStream s)
{
byte[] buffer = new byte[0];
byte[] chunk = new byte[4096];
int count;
try{
while((count = s.read(chunk))>=0)
{
byte[] t = new byte[buffer.length+count];
System.arraycopy(buffer,0,t,0,buffer.length);
System.arraycopy(chunk,0,t,buffer.length,count);
buffer=t;
}
}catch(Exception e){}
return buffer;
} //初始化配置信息
public GetTif(BufferedReader brin)
{
if(brin==null)return;
try{
this.Url=brin.readLine().trim();
this.JdbcUser = brin.readLine().trim();
this.JdbcPwd = brin.readLine().trim();
brin.close();
}catch(IOException ex)
{System.err.println("FileIOError:"+ex);}
} //读数据库
private void readDB()
{
//注册数据库驱动程序
try{
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
}
catch(Exception e)
{System.err.println("注册数据库驱动程序错误:" + e);}
//从数据库读OLE或附件
try{
Connection con = DriverManager.getConnection(Url,JdbcUser,JdbcPwd);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM image_files");
java.math.BigDecimal DocNo; InputStream inTif;
while(rs.next()){
try{
DocNo = rs.getBigDecimal("NO",0);
inTif = rs.getBinaryStream("TIF");
saveFile(DocNo.toString(),inTif);
System.out.println("存储过度Tif文件:"+DocNo.toString());
}
catch(Exception e)
{System.err.println("存储过度文件错误:" + e);}
}
st.close();
con.close();
}
catch(Exception e)
{System.err.println("数据库查询错误:" + e);}
} public static void main(String args[])
{
GetTif gt = new GetTif(getBufferedReader("d:\\documents\\GetOLE\\class\\odbc.ini"));
gt.readDB();
}
}
jdbc:odbc:testOle
test
test