能!create table testimg (a int,b image);
go
insert testimg (a,b) values (2,'test');
再到DOS下执行
textcopy /S SERVERNAME /U sa /P /D Northwind /T testimg /C b /W "where a = 2 " /F f:\tmp\1.ico /I /Z
go
insert testimg (a,b) values (2,'test');
再到DOS下执行
textcopy /S SERVERNAME /U sa /P /D Northwind /T testimg /C b /W "where a = 2 " /F f:\tmp\1.ico /I /Z
解决方案 »
- |zyciis| 如何设计数据库记录的排序问题,谢谢
- image 字段~~~~
- 请教大家计算Category下面Products的数量
- 新旧编码转换
- CreateInstance("ADODB.Connection") 不支持此接口?
- 有关varchar字段和text字段
- 帮忙!!!在线等————帮我看看这个存储过程什么地方不对
- 急死我了!!!!!!!
- SQl SERVER 客户端连接端口
- 使用SQL2000时,打开一个表,用“返回所有行”的方式,系统弹出“内部错误,构造不完整”的信息窗口,这要怎么解决?怎么才能浏览一个数SQL数据库表???
- 500分-----提供思路或解决者,马上给分。问题:“错误信息:代理程序处于置疑状态,在最近10分钟内没有响应-???”
- 我把doc、jpeg、text等文件写入sql2000的image类型字段中,现在希望把它们从image中读出并生成一个文件,或者直接显示在网页上,用asp.net
"
也可以的.
下面是一个拷贝图像到SQL Server的pubs数据库的例子, 表名pub_info, 字段名logo,图像文件名picture.bmp,保存到pub_id='0736'记录
sp_textcopy @srvn
ame = 'ServerName',
@login = 'Login',
@password = 'Password',
@dbname = 'pubs',
@tbname = 'pub_info',
@colname = 'logo',
@filename = 'c:\picture.bmp',
@whereclause = " WHERE pub_id='0736' ",
@direction = 'I'
@srvname varchar (30),
@login varchar (30),
@password varchar (30),
@dbname varchar (30),
@tbname varchar (30),
@colname varchar (30),
@filename varchar (30),
@whereclause varchar (40),
@direction char(1))
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
'textcopy /S ' + @srvname +
' /U ' + @login +
' /P ' + @password +
' /D ' + @dbname +
' /T ' + @tbname +
' /C ' + @colname +
' /W "' + @whereclause +
'" /F ' + @filename +
' /' + @direction
EXEC master..xp_cmdshell @exec_str
sun自带的jdbc-odbc桥的驱动,用sql server2000。
import java.util.*;
import java.io.*;
import java.sql.*;
import java.lang.*;
/**将一个图像文件保存到数据库中
*/
public class ImageTry {
public static void main(String[] args){
Connection conn = getConnection();
PreparedStatement pstm =null;
Statement stm =null;
ResultSet res = null;
FileInputStream fin = null;
try{
File f = new File("image.jpg");
fin = new FileInputStream(f);
String sql_1=" insert into table1(col_02) values(?)";
//列col_02是image类型的
pstm = conn.prepareStatement(sql_1);
pstm.setBinaryStream(1,fin,(int)f.length());
pstm.executeUpdate();
fin.close();
stm = conn.createStatement();
String sql_2="select col_02 from table1";
res = stm.executeQuery(sql_2);
if(res!= null && res.next()){
outImage(res.getBinaryStream("col_02"));
}
}catch(Exception e){
e.printStackTrace(System.out);
}finally{
if(fin != null){
try{
fin.close();
}catch(IOException e){}
}
if(res != null){
try{
res.close();
}catch(SQLException e){}
}
if(stm != null){
try{
stm.close();
}catch(SQLException e){}
}
if(pstm != null){
try{
pstm.close();
}catch(SQLException e){}
}
if(conn != null){
try{
conn.close();
}catch(SQLException e){}
}
}
}
/**
* 写到一个文件
*/
static void outImage( InputStream din)
throws IOException{
File f = new File("im.jpg");
FileOutputStream fout = null;
try{
fout = new FileOutputStream(f);
int b ;
while((b = din.read() )!=-1){
fout.write(b);
}
}finally{
if(din != null){
try{
din.close();
}catch(IOException e){}
}
if(fout != null){
try{
fout.close();
}catch(IOException e){}
}
}
}
/**取出一个连接
*/
public static Connection getConnection(){
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:Test;UID=sa;PWD=";
Connection ObjectCon=null;
try{
Class.forName(sDBDriver);
ObjectCon=DriverManager.getConnection(sConnStr);
}catch(Exception Error){
System.out.println(Error);
}
return ObjectCon;
}
}
delphi:
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ADOTable1.Append;
TBlobField(ADOTable1.FieldByName('FImage')).LoadFromFile(OpenPictureDialog1.FileName);
ADOTable1.Post;
end;
还是bcb:
if(DATABASE_STATE==INSERT)
{
AnsiString st;
TMemoryStream *tmp = new TMemoryStream();
DBI1->Picture->SaveToFile("TTT.jpg");
tmp->LoadFromFile("TTT.jpg");
DeleteFile("TTT.jpg");
ADOQuery1->Parameters->ParamByName("PIC")->LoadFromStream(tmp,ftBlob);
ADOQuery1->Parameters->ParamByName("TD")->Value=DP1->Date;
st="摄于"+ DP1->Date;
ADOQuery1->Parameters->ParamByName("JPEG")->Value=JpegOrBmp?"BMP":"JPEG";
ADOQuery1->Parameters->ParamByName("IDI")->Value=MEM1->Text + st;
ADOQuery1->Parameters->ParamByName("HEI")->Value=BT->Height;
ADOQuery1->Parameters->ParamByName("WID")->Value=BT->Width;
ADOQuery1->ExecSQL();
ShowMessage("保存" + IntToStr(tmp->Size ));
ShowMessage("成功保存图片!");
delete tmp;
return;
}
还是上面写的java??
答题要有题目才行呀!你考试都不看题目的吗?
你可以参考一下,有时间再和你多聊一下
public void myInsert()
{
Int32 intFileLength;
string strFileType;
string strFileName;
Stream stmFile;
strFileName="";
strFileName=FileBox1.PostedFile.FileName;
intFileLength=FileBox1.PostedFile.ContentLength;
strFileType=FileBox1.PostedFile.ContentType;
//strFileType="dd";
stmFile=FileBox1.PostedFile.InputStream;
byte[] ByteFile=new byte[intFileLength];
stmFile.Read(ByteFile,0,intFileLength);
/*
FileStream fs = new FileStream("aa.doc", FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] DocByte = br.ReadBytes((int)fs.Length);
fs.Close();
*/
SqlConnection myCon=new SqlConnection("server=(local);database=test;uid=sa;pwd=");
string strCom="INSERT INTO FileByField Values(@Name,@FileData,@FileType,@FileLength)";
SqlCommand myCom=new SqlCommand(strCom,myCon);
myCom.Parameters.Add("@Name",SqlDbType.Char,255);
myCom.Parameters.Add("@FileData",SqlDbType.Image);
myCom.Parameters.Add("@FileType",SqlDbType.Char,255);
myCom.Parameters.Add("@FileLength",SqlDbType.BigInt);
myCom.Parameters["@Name"].Value=strFileName;
myCom.Parameters["@FileData"].Value=ByteFile;
myCom.Parameters["@FileType"].Value=strFileType;
myCom.Parameters["@FileLength"].Value=intFileLength;
myCon.Open();
try
{ myCom.ExecuteNonQuery(); }
catch(SqlException e)
{
if(e.Number==2627)
Response.Write("PrimaryKey Error");
else
Response.Write("Other Error");
}
myCon.Close();
BindData();
}