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控制項,把引用的地址指向這個頁面就行了
問題十:如何像資料庫中保存圖片? 一般圖像是不保存在資料庫的.而是先將圖片放在工程下的某個文件夾中,將圖片所在的工程文件路徑存在資料庫中,當程序載入圖片的時候,從資料庫中讀取圖片的路徑,然後根據路徑在工程的文件夾中讀取圖片文件