当前位置:首页 » 编程语言 » sqlserver保存图片

sqlserver保存图片

发布时间: 2025-07-09 08:04:14

Ⅰ ASP.NET如何存取 sqlServer数据库图片

SQL Server提供了一个特别的数据类型 image 它是一个包含binary数据的类型 下边这个例子就向你展示了如何将文本或照片放入到数据库中的办法 在这篇文章中我们要看到如何在SQL Server中存储和读取图片 建立一个表 在SQL SERVER中建立这样结构的一个表

列名 类型 目的 ID Integer 主键ID IMGTITLE Varchar( ) 图片的标题 IMGTYPE Varchar( ) 图片类型 ASP NET要以辨认的类型 IMGDATA Image 用于存储二进制数据 IMGTYPE Varchar( ) 图片类型 ASP NET要以辨认的类型 IMGDATA Image 用于存储二进制数据

存储图片到SQL SERVER数据库中 为了能存储到表中 你首先要上传它们到你的WEB 服务器上 你可以开发一个web form 它用来将客户端中TextBox web control中的图片入到你的WEB服务器上来 将你的 encType 属性设置为 myltipart/formdata Stream imgdatastream = File PostedFile InputStream;int imgdatalen = File PostedFile ContentLength;string imgtype = File PostedFile ContentType;string imgtitle = TextBox Text;byte[] imgdata = new byte[imgdatalen];int n = imgdatastream Read(imgdata imgdatalen);string connstr=((NameValueCollection)Context GetConfig( appSettings ))[ connstr ];SqlConnection connection = new SqlConnection(connstr);SqlCommand mand = new SqlCommand( INSERT INTO ImageStore(imgtitle imgtype imgdata)VALUES ( @imgtitle @imgtype @imgdata ) connection );SqlParameter paramTitle = new SqlParameter( @imgtitle SqlDbType VarChar );paramTitle Value = imgtitle;mand Parameters Add( paramTitle);SqlParameter paramData = new SqlParameter( @imgdata SqlDbType Image );paramData Value = imgdata;mand Parameters Add( paramData );SqlParameter paramType = new SqlParameter( @imgtype SqlDbType VarChar );paramType Value = imgtype;mand Parameters Add( paramType );connection Open();int numRowsAffected = mand ExecuteNonQuery();connection Close(); 从数据库中恢复读取 现在让我们来从SQL Server中读取我们放入的数据吧!我们将要输出图片到你的浏览器上 你也可以将它存放到你要的位置 private void Page_Load(object sender System EventArgs e){string imgid =Request QueryString[ imgid ];string connstr=((NameValueCollection)Context GetConfig( appSettings ))[ connstr ];string sql= SELECT imgdata imgtype FROM ImageStore WHERE id = + imgid;SqlConnection connection = new SqlConnection(connstr);SqlCommand mand = new SqlCommand(sql connection);connection Open();SqlDataReader dr = mand ExecuteReader();if(dr Read()){Response ContentType = dr[ imgtype ] ToString();Response BinaryWrite( (byte[]) dr[ imgdata ] );}connection Close();} 要注意的是Response BinaryWrite 而不是Response Write

下面给大家一个用于C# Winform的存入 读取程序 其中不同请大家自己比较!(为了方便起见 我将数据库字段简化为二个 imgtitle和imgdata using System;using System Drawing;using System Collections;using System ComponentModel;using System Windows Forms;using System Data;using System IO;using System Data SqlClient;namespace WindowsApplication {/// <summary>/// Form 的摘要说明 /// </summary>public class Form : System Windows Forms Form{private System Windows Forms Button button ;/// <summary>/// 必需的设计器变量 /// </summary>private System ComponentModel Container ponents = null;private string ConnectionString = Integrated Security=SSPI;Initial Catalog=;DataSource=localhost; ;private SqlConnection conn = null; private SqlCommand cmd = null;private System Windows Forms Button button ;private System Windows Forms PictureBox pic ;private System Windows Forms OpenFileDialog openFileDialog ;private string sql = null;private System Windows Forms Label label ;private string nowId=null;public Form (){//// Windows 窗体设计器支持所必需的//InitializeComponent();conn = new SqlConnection(ConnectionString); //// TODO: 在 InitializeComponent 调用后添加任何构造函数代码//}/// <summary>/// 清理所有正在使用的资源 /// </summary>protected override void Dispose( bool disposing ){if (conn State == ConnectionState Open)conn Close();if( disposing ){if (ponents != null) {ponents Dispose();}}base Dispose( disposing );}#region Windows Form Designer generated code/// <summary>/// 设计器支持所需的方法 不要使用代码编辑器修改/// 此方法的内容 /// </summary>private void InitializeComponent(){this button = new System Windows Forms Button();this pic = new System Windows Forms PictureBox();this button = new System Windows Forms Button();this openFileDialog = new System Windows Forms OpenFileDialog();this label = new System Windows Forms Label();this SuspendLayout();// // button // this button Location = new System Drawing Point( );this button Name = button ;this button Size = new System Drawing Size( );this button TabIndex = ;this button Text = 加入新的图片 ;this button Click += new System EventHandler(this button _Click);// // pic // this pic Location = new System Drawing Point( );this pic Name = pic ;this pic Size = new System Drawing Size( );this pic TabIndex = ;this pic TabStop = false;// // button // this button Location = new System Drawing Point( );this button Name = button ;this button Size = new System Drawing Size( );this button TabIndex = ;this button Text = 从数据库中恢复图像 ;this button Click += new System EventHandler(this button _Click);// // openFileDialog // this openFileDialog Filter = 图像文件(* jpg * bmp * gif)|* jpg|* bmp|* gif ;// // label // this label Location = new System Drawing Point( );this label Name = label ;this label Size = new System Drawing Size( );this label TabIndex = ;// // Form // this AutoScaleBaseSize = new System Drawing Size( );this ClientSize = new System Drawing Size( );this Controls AddRange(new System Windows Forms Control[] {this label this button this pic this button });this Name = Form ;this Text = Form ;this Load += new System EventHandler(this Form _Load);this ResumeLayout(false);}#endregion

lishixin/Article/program/net/201311/11512

Ⅱ (DELPHI)已经存入SQLSERVER中的图片数据(image字段)太大,怎么直接在数据库中压缩或怎么用程序实现

delphi 的图像缩放示例代码如下:

//将图片缩放至指定大小
procereSizeBmp(constSource,Dest:string;constx,y:integer);
var
aBmp,bBmp:tbitmap;
scalex,scaley:real;
begin
aBmp:=TBitmap.Create;
bBmp:=TBitmap.Create;
try
aBmp.LoadFromFile(Source);
scaley:=aBmp.Height/y;
scalex:=aBmp.Width/x;
bBmp.Width:=round(aBmp.Width/scalex);
bBmp.Height:=round(aBmp.Height/scaley);
bBmp.PixelFormat:=pfDevice;
SetStretchBltMode(bBmp.Canvas.Handle,COLORONCOLOR);
StretchBlt(bBmp.Canvas.Handle,0,0,bBmp.Width,bBmp.Height,
aBmp.Canvas.Handle,0,0,aBmp.Width,aBmp.Height,src);
bBmp.SaveToFile(Dest);
finally
aBmp.Free;
bBmp.Free;
end;
end;

procereTForm1.btn1Click(Sender:TObject);
begin
SizeBmp('e:1112.bmp','e:1112_small.bmp',640,480);
end;

Ⅲ Sqlserver数据库存储的图片格式(二进制数据)怎么显示到页面

1.将图片以二进制存入数据库
//保存图片到数据库
protected void Button1_Click(object sender, EventArgs e)
{
//图片路径
string strPath = "~/photo/03.JPG";
string strPhotoPath = Server.MapPath(strPath);
//读取图片
FileStream fs = new System.IO.FileStream(strPhotoPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
//存入
SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
string strComm = " INSERT INTO personPhoto(personName, personPhotoPath, personPhoto) ";
strComm += " VALUES('wangwu', '" + strPath + "', @photoBinary )";
SqlCommand myComm = new SqlCommand(strComm, myConn);
myComm.Parameters.Add("@photoBinary", SqlDbType.Binary,photo.Length);
myComm.Parameters["@photoBinary"].Value = photo;
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
}
2.读取二进制图片在页面显示
//读取图片
SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
string strComm = " SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ";
SqlCommand myComm = new SqlCommand(strComm, myConn);
myConn.Open();
SqlDataReader dr = myComm.ExecuteReader();
while (dr.Read())
{
byte[] photo = (byte[])dr["personPhoto"];
this.Response.BinaryWrite(photo);
}
dr.Close();
myConn.Close();

SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);
DataSet myds = new DataSet();
myConn.Open();
myda.Fill(myds);
myConn.Close();
byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];
this.Response.BinaryWrite(photo);
3.设置Image控件显示从数据库中读出的二进制图片
---------------------------------------------
SqlConnection myConn = new SqlConnection("Data Source=192.168.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);
DataSet myds = new DataSet();
myConn.Open();
myda.Fill(myds);
myConn.Close();
byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];
//图片路径
string strPath = "~/photo/wangwu.JPG";
string strPhotoPath = Server.MapPath(strPath);
//保存图片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath,FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
3.显示图片
this.Image1.ImageUrl = strPath;
4.GridView中ImageField以URL方式显示图片
--------------------------
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="personName" HeaderText="姓名" />
<asp:ImageField DataImageUrlField="personPhotoPath"
HeaderText="图片">
</asp:ImageField>
</Columns>
</asp:GridView>
5.GridView显示读出的二进制图片
//样板列
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="personName" HeaderText="姓名" />
<asp:ImageField DataImageUrlField="personPhotoPath"
HeaderText="图片">
</asp:ImageField>
<asp:TemplateField HeaderText="图片">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex < 0)
return;
// System.ComponentModel.Container
string strPersonName = (string)DataBinder.Eval(e.Row.DataItem, "personName");
Image tmp_Image = (Image)e.Row.Cells[2].FindControl("Image1");
if (!System.Convert.IsDBNull(DataBinder.Eval(e.Row.DataItem, "personPhoto")))
{
//
byte[] photo = (byte[])DataBinder.Eval(e.Row.DataItem, "personPhoto");
//图片路径
string strPath = "~/photo/" + strPersonName.Trim() + ".JPG";
string strPhotoPath = Server.MapPath(strPath);
//保存图片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
//显示图片
tmp_Image.ImageUrl = strPath;
}
}

Ⅳ 如何用vb向sql数据库存取照片 最好有事例 谢谢

在VB中存取数据库中的图片
2001-07-05·
·史美康
··vbeden.com
一、
数据库的设计
数据库可以采用微软的Access97或者SQL
Server来进行,首先新建一张表,取名为Table,添加三个字段,分别是:姓名
Char型(SQL
Server中)文本型(Access中);编号Char型(SQL
Server中)文本型(Access中);照片image型(SQL
Server中)OLE对象(Access中),设计好后存盘。为了可以进行远程调用,我们采用ODBC的方法进行,双击打开控制面板里的ODBC数据源,点“系统DSN”选项卡,按“添加”按钮选择对应的数据源驱动程序Access的*.mdb或者SQL
Server,依照添加向导加添加数据源,下面就可以开始程序的编写了。
二、
程序的编写
运行VB,新建一个工程。本程序采用ADO控件和动态链接库访问数据库,需要加入ADO的运行库,单击“工程\引用”菜单,出现引用对话框,选择Microsoft
ActiveX
Data
Objects2.0
Library并确定。
添加一个Form,四个Label控件,两个TextBox控件,一个PictureBox控件,一个ADODC控件,三个CommandButton控件,一个CommandDialog控件,如果ADODC和CommandDialog控件没有出现在工具框上,请单击菜单“工程\部件”。点“控件”选项卡,在其中选中Microsoft
ADO
Data
Control
6.0(OLEDB)和Microsoft
Common
Dialog
Control
6.0两项按“确定”按钮。
下面是以上各个控件的一些属性:
Form1.MaxButton=False
Label1.Caption=姓名:
Label2.Caption=编号:
Label3.Name=
ResName
Label3.BackColor=
&H80000009&
Label3.BorderStyle=1-Fixed
Single
Label3.DataField=姓名
Label3.DataSource=
AdoCtr
Label4.Name=
ResNumb
Label4.BackColor=
&H80000009&
Label4.BorderStyle=1-Fixed
Single
Label4.DataField=编号
Label4.DataSource=
AdoCtr
Text1.Name=
Names
Text2.Name=
Numb
CommonDialog1.Name=
CDlg
Adodc1.Name=AdoCtr
CommonButton1.Name=PreView
CommonButton1.Caption=预览
CommonButton2.Name=Save
CommonButton2.Caption=保存
CommonButton3.Name=
Update
CommonButton3.Caption=更新
PictureBox1.Name=
PicBox
PictureBox1.AutoSize=False
PictureBox1.AutoRedraw=False
PictureBox1.DataField=照片
PictureBox1.DataSource=AdpCtr
下面是程序代码:
′此工程需有Microsoft
ActiveX
Data
Object
2.1
Library(msado15.dll)
Dim
Constr
As
String
′ODBC路径
Dim
FileName
As
String
′图片文件名
Const
BLOCKSIZE
=
4096
′每次读写块的大小
Dim
ADOCon
As
New
ADODB.Connection
′ADODB
Connection对象
Dim
ADORst
As
New
ADODB.Recordset
′ADODB
Recordset
对象
Dim
ADOFld
As
ADODB.Field
′ADODB
Field
对象
------------------------
Private
Sub
SaveToDB(ByRef
Fld
As
ADODB.Field,
DiskFile
As
String)
Dim
byteData()
As
Byte
′定义数据块数组
Dim
NumBlocks
As
Long
′定义数据块个数
Dim
FileLength
As
Long
′标识文件长度
Dim
LeftOver
As
Long′定义剩余字节长度
Dim
SourceFile
As
Long
′定义自由文件号
Dim
i
As
Long
′定义循环变量
SourceFile
=
FreeFile
′提供一个尚未使用的文件号
Open
DiskFile
For
Binary
Access
Read
As
SourceFile
′打开文件
FileLength
=
LOF(SourceFile)
′得到文件长度
If
FileLength
=
0
Then
′判断文件是否存在
Close
SourceFile
MsgBox
DiskFile
&








!〃
Else
NumBlocks
=
FileLength
\
BLOCKSIZE
′得到数据块的个数
LeftOver
=
FileLength
Mod
BLOCKSIZE
′得到剩余字节数
Fld.Value
=
Null
ReDim
byteData(BLOCKSIZE)
′重新定义数据块的大小
For
i
=
1
To
NumBlocks
Get
SourceFile,
,
byteData()

读到内存块中
Fld.AppendChunk
byteData()
′写入FLD
Next
i
ReDim
byteData(LeftOver)
′重新定义数据块的大小
Get
SourceFile,
,
byteData()
′读到内存块中
Fld.AppendChunk
byteData()
′写入FLD
Close
SourceFile
′关闭源文件
End
If
End
Sub
----------------------
Private
Sub
Form_Load()
Constr
=
〃DSN=image〃
′定义ODBC连接
ADOCon.Open
Constr
′创建一个连接
ADORst.Open
〃table〃,
ADOCon,
adOpenDynamic,
adLockOptimistic
′打开一个ADO动态集
表名为table
Set
AdoCtr.Recordset
=
ADORst
′将动态集赋给ADO控件
End
Sub
----------------------
Private
Sub
Form_Unload(Cancel
As
Integer)
′记得关闭打开的数据集,释放资源
ADORst.Close
ADOCon.Close
Set
ADORst
=
Nothing
Set
ADOCon
=
Nothing
End
Sub
----------------------
Private
Sub
PreView_Click()
′显示打开文件的公用对话框,选择需要加入数据库的图片
CDlg.Filter
=
〃位图(*.bmp)|*.bmp〃
CDlg.ShowOpen
FileName
=
CDlg.FileName
PicBox.Picture
=
LoadPicture(FileName)
′预览图片
End
Sub
----------------------
Private
Sub
Save_Click()
ADORst.AddNew
′新增纪录
ADORst(〃姓名〃).Value
=
Names.Text
′给动态集的第一个字段赋值
ADORst(〃编号〃).Value
=
Numb.Text
′给动态集的第二个字段赋值
Set
ADOFld
=
ADORst(〃照片〃)
′给ADODB.Field对象赋值
Call
SaveToDB(ADOFld,
FileName)
′调用子程序,给第三个字段(image)赋值
ADORst.Update
End
Sub
----------------------
Private
Sub
Update_Click()
′重新打开纪录集,刷新纪录
ADORst.Close
ADOCon.Close
Set
ADORst
=
Nothing
Set
ADOCon
=
Nothing
ADOCon.Open
Constr
ADORst.Open
〃table〃,
ADOCon,
adOpenDynamic,
adLockOptimistic
Set
AdoCtr.Recordset
=
ADORst
End
Sub

Ⅳ sql如何存储sql如何存储照片

使用SQL语句创建存储过程

使用SQL语句创建存储的具体过程如下:

1.首先,打开企业管理器并选择工具-查询分析器:

2.然后,输入SQL语句。如下所示:

创建过程byroyalty1@percentageint

如同

从标题作者中选择au_id

其中titleauthor.royaltyper=@percentage

3.然后,单击“确定”后,该命令将自动添加到查询中:

4.然后执行刚刚输入的命令:

5.最后,您可以在小弹出窗口中查看存储过程:

SQL数据存储图片常用的方法?

1.先存储图片链接了,这里先要设置图片链接字段,如下图所示。

2.接着就是直接将图片的链接添加到SQL数据表的字段里就行了,如下图所示。

3.另外还可以用二进制的方式存储图片字段,如下图所示,在SQLServer数据库中先设计成image字段,如下图所示。

4.接着在后台通过代码将图片转化为二进制数据,如下图所示。

5.接下来得到二进制数据以后,一般就是通过sql语句插入到数据表中,如下图所示。

6.然后数据表就存储了图片字段了,取得时候在将二进制转化为图片就行了。

7.最后不同的数据库二进制字段类型是不一样得,如下图所示mysql是blob。

完成以上步骤即可完成。

sqlserver2008怎么建立储存过程?

第一步:点击数据库下的“可编程性”,选择“存储过程”,点击鼠标右键,选择“新建存储过程”

第二步:在createPROCEDURE后输入存储过程的名字,紧跟着的就是定义存储过程的参数,接下来就可以去编写自己所需要组装的存储过程语句了第三步:编译存储过程,在工具栏上按下执行按钮,如果没有错误,就编写成功了。

第四步:调用:在sqlserver的语句查询框中,输入exec存储过程名参数,执行就可以了。基本语法格式如下:中括号带的是可选项createproc|procerepro_name,{@参数数据类型},....]asbeginSQL_statements--业务处理end

sqlserver怎么创建存储过程?

1、打开SQLservermanagementstudio,连接到数据库,展开想要创建的数据库,找到【可编程性】->【存储过程】的菜单。

2、在第一步找到的【存储过程】菜单项上面,点击鼠标右键,依次选择【新建】->【存储过程】,就可以开始创建存储过程了。

3、当点击了第二步的【存储过程】之后,在右侧就会出现一个新的窗口,而且默认有好多的代码和注释,这些就是sqlserver默认创建的存储过程的结构和注释。

4、如图为sqlserver默认创建的存储过程的结构和注释的中文解释。

5、此处仅仅创建一个简单的演示存储过程,名字叫做usp_SimpleStoreProcere,拥有一个整型的传入参数@x,存储过程直接返回传入参数乘以10倍的结果。写完存储过程之后,按F5就可以将其存储到数据库中。

6、在第二步中找到的【存储过程】菜单下面找到第5步创建的存储过程名字usp_SimpleStoreProcere,在这个名字上面点击鼠标右键,选择【执行存储过程】。

7、紧接着,会弹出一个【执行过程】的界面,里面有存储过程的参数,在【值】这一列输入想要传入的参数值,比如10,然后点击【确定】按钮,就可以看到执行结果100了。

sql调用存储过程?

sql调用存储过程:存储过程里用exec执行另一存储过程名及它需要的参数就可以了如execabcƇ',ƈ'(abc是存储过程的名字,Ƈ',ƈ'是它的参数。

拓展资料:

结构化查询语言是高级的非过程化编程语言,允许用户在高层数据结构上工作。它不要求用户指定对数据的存放方法,也不需要用户了解具体的数据存放方式,所以具有完全不同底层结构的不同数据库系统,可以使用相同的结构化查询语言作为数据输入与管理的接口。结构化查询语言语句可以嵌套,这使它具有极大的灵活性和强大的功能。

sqlserver里存储过程怎么调用存储过程?

sqlserver里调用存储过程的具体操作步骤如下:1、打开SQLServerManagment管理工具,新建一个表。

2、然后在表中插入一些样例数据。3、接下来在SQLServerManagment中右键单击可编程性,选择新建存储过程。4、然后在SQL编写界面中编写SQL语句,注意这里的@name就是接收的输入参数。5、编写好存储过程,执行一下,就会在可编程性下面找到创建的存储过程。6、紧接着,会弹出一个【执行过程】的界面,里面有存储过程的参数,在【值】这一列输入想要传入的参数值,比如10,然后点击【确定】按钮,就可以看到执行结果100了。

Ⅵ 数据库能存图片吗

问题一:数据库怎样可以将图片放到里面 首先肯定一点,数据库中是可以放图片数据的!但是这样的话,数据体积会很庞大,当然最好还是把图片放到文件夹中,数据只用来存放图片路径,不过最好是存放相对路径,应该以后可能设计到图片单独放在另一台服务器上,或换了文件夹。

问题二:SQL数据库中能存照片吗? 图片完全可以存放,但是在数据库中不能以select * from a进行查询
但是在相对应得c#、java中可以查询
是以二进制保存的。

数据库,只要是抽象出来的数据,都可以保存。
而已不能保存的,就是实体,像处啊、鞋子啊、男朋友啊都不姓

问题三:mysql数据库可以存图片吗? 可以。存图片的列需要设置成BLOB、MEDIUMBLOB或LONGBLOB等数据类型。
但是以前基本上不会把图片直接存在数据库里,因为数据库里的数据是为了用来快速分析、快速存取的,图片数据在mysql里既不能建立索引也不能和其他数据一起分析,存取速度和读写磁盘也没什么区别,每次备份、导入导出数据库时还增加了数据量,降低了效率。所以一般都是把图片存在系统里,然后把图片的存放路径放在数据库里。

问题四:图片如何存入数据库 第一种方式:保存图片路径至数据库中
第二种方式:数据插入相应表中,参数类型为byte[]
例如:
sql:insert into table(imageColumn) values (@image);
其中@image参数值为byte[]类型的变量

问题五:图片如何存放在oracle数据库 测试可行。这只是核心Class文件代码,你要是弄不出来,就再联系我,我再把整个项目给你。这是把图片真个放到数据库
package .;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;
import oracle.sql.BLOB;
public class Insert {
Scanner sc =new Scanner(System.in);
@SuppressWarnings(deprecation)
public int insertbinary(String pname,String src1){
Connection con = null;
String sql = insert into test values(?,?);
String sql1 =update test set image=? where pname=?;
int res = 0;
try {
con=BaseDAO.getConnection();
con.setAutomit(false);
PreparedStatement pstm = con.prepareStatement(sql);
pstm.setString(1, pname);
EMPTY_BLOB和EMPTY_CLOB返回一个空的LOB定位器,
可以用来初始化一个LOB变量,或在INSERT或UPDATE语句,
初始化LOB列或属性为空。 EMPTY表示LOB初始化,但不填充数据。
pstm.setBlob(2, oracle.sql.BLOB.empty_lob());
pstm.executeUpdate();
pstm.close();
pstm = con.prepareStatement(select * from test where pname=?);
pstm.setString(1, pname);
ResultSet rs = pstm.executeQuery();
rs.next();
BLOB blob = (BLOB) rs.getBlob(2);
OutputStream os = blob.getBinaryOutputStream();
FileInputStream fi = new FileInputStream(src1);
byte[] buff = new byte[1024];
int len = fi.read(buff);
while (len != -1) {
os.write(buff);
len = fi.read(buff);
}
pstm = con.prepareStatement(sql1);
pstm.setBlob(1,......>>

问题六:如何将图片储存在MySQL数据库里 通常对用户上传的图片需要保存到数据库中。解决方法一般有两种:一种是将图片保存的路径存储到数据库;另一种是将图片以二进制数据流的形式直接写入数据库字段中。以下为具体方法:
一、保存图片的上传路径到数据库:
string uppath=;用于保存图片上传路径
获取上传图片的文件名
string fileFullname = this.FileUpload1.FileName;
获取图片上传的时间,以时间作为图片的名字可以防止图片重名
string dataName = DateTime.Now.ToString(yyyyMMddhhmmss);
获取图片的文件名(不含扩展名)
string fileName = fileFullname.Substring(fileFullname.LastIndexOf(\\) + 1);
获取图片扩展名
string type = fileFullname.Substring(fileFullname.LastIndexOf(.) + 1);
判断是否为要求的格式
if (type == bmp || type == jpg || type == jpeg || type == gif || type == JPG || type == JPEG || type == BMP || type == GIF)
{
将图片上传到指定路径的文件夹
this.FileUpload1.SaveAs(Server.MapPath(~/upload) + \\ + dataName + . + type);
将路径保存到变量,将该变量的值保存到数据库相应字段即可
uppath = ~/upload/ + dataName + . + type;
}
二、将图片以二进制数据流直接保存到数据库:
引用如下命名空间:
using System.Drawing;
using System.IO;
using System.Data.SqlClient;
设计数据库时,表中相应的字段类型为iamge
保存:
图片路径
string strPath = this.FileUpload1.PostedFile.FileName.ToString ();
读取图片
FileStream fs = new System.IO.FileStream(strPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int......>>

问题七:如何在数据库中存储图片文件 解决方法一般有两种:
一种是将图片保存的路径存储到数据库;
另一种是将图片以二进制数据流的形式直接写入数据库字段中。

问题八:如何将图片存到数据库 通常对用户上传的图片需要保存到数据库中。解决方法一般有两种:一种是将图片保存的路径存储到数据库;另一种是将图片以二进制数据流的形式直接写入数据库字段中。以下为具体方法:
一、保存图片的上传路径到数据库:
string uppath=;用于保存图片上传路径
获取上传图片的文件名
string fileFullname = this.FileUpload1.FileName;
获取图片上传的时间,以时间作为图片的名字可以防止图片重名
string dataName = DateTime.Now.ToString(yyyyMMddhhmmss);
获取图片的文件名(不含扩展名)
string fileName = fileFullname.Substring(fileFullname.LastIndexOf(\\) + 1);
获取图片扩展名
string type = fileFullname.Substring(fileFullname.LastIndexOf(.) + 1);
判断是否为要求的格式
if (type == bmp || type == jpg || type == jpeg || type == gif || type == JPG || type == JPEG || type == BMP || type == GIF)
{
将图片上传到指定路径的文件夹
this.FileUpload1.SaveAs(Server.MapPath(~/upload) + \\ + dataName + . + type);
将路径保存到变量,将该变量的值保存到数据库相应字段即可
uppath = ~/upload/ + dataName + . + type;
}
二、将图片以二进制数据流直接保存到数据库:
引用如下命名空间:
using System.Drawing;
using System.IO;
using System.Data.SqlClient;
设计数据库时,表中相应的字段类型为iamge
保存:
图片路径
string strPath = this.FileUpload1.PostedFile.FileName.ToString ();
读取图片
FileStream fs = new System.IO.FileStream(strPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br......>>

问题九:怎样数据库access保存jpg图片 只有两种方法
1.存图片地址,图片放服务器的一个文件夹里
2.存图片的数据,也就是二进制流
既然第一种你说不行 那只能第二种了。
我只说一下思路,代码网上找一下,多的很,也不麻烦1.数据库字段类型为image(sqlserver的是image,不知道access的是不是)
2.把图片文件序列化 放到一个byte[]数组里,然后存到数据库
显示的时候:
1.单独在一个页面读出图片的内容到一个byte[]数组
2.用response把这段二进制输出
3.在要引用的地方,比如你的image控件,把引用的地址指向这个页面就行了

问题十:如何像数据库中保存图片? 一般图像是不保存在数据库的.而是先将图片放在工程下的某个文件夹中,将图片所在的工程文件路径存在数据库中,当程序加载图片的时候,从数据库中读取图片的路径,然后根据路径在工程的文件夹中读取图片文件

热点内容
数据库逻辑存储结构 发布:2025-07-10 09:26:56 浏览:920
密码编译找规律 发布:2025-07-10 09:18:10 浏览:512
电影视频缓存后 发布:2025-07-10 09:16:48 浏览:894
服务器搭建需要哪些东西 发布:2025-07-10 09:15:23 浏览:802
无限密码怎么改 发布:2025-07-10 09:14:32 浏览:106
coc按键精灵脚本 发布:2025-07-10 09:12:40 浏览:313
excel表格ftp函数 发布:2025-07-10 09:05:50 浏览:278
u2game的解压密码 发布:2025-07-10 09:05:14 浏览:598
c语言编译器ide苹果下载 发布:2025-07-10 09:05:13 浏览:295
andftp端口 发布:2025-07-10 08:57:04 浏览:609