⑴ web图片一般存在后端哪里
web图片一般存在Java后端。
web前端上传图片到Java后端,并保存到本地。一般来说,图片在后端的存储方式分为两种:一,可以将图片以独立文件的形式存储在服务器的指定文件夹中,再将路径存入数据库字段中,二,将图片转换成二进制流,直接存储到数据库的Image类型字段中。
⑵ 如何才能往数据库里读取图片数据或者从数据库里读图片
给你提供个ACCESS版的VB代码,使用时调用这些过程即可:
'使用ADODB.Stream来保存/读取图像文件到数据库
'引用Microsoft ActiveX Data Objects 2.5 Library及以上版本
'保存文件到数据库中
Sub SaveFile()
Dim Stm As New ADODB.Stream
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCnn As String
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & _
App.Path & "\DB1.mdb"
Cnn.Open strCnn
'读取文件到内存(二进制模式)
With Stm
.Type = adTypeBinary
.Open
.LoadFromFile App.Path + "\Image1.bmp"
End With
With rs
.Open "SELECT * FROM TABLE1", Cnn, 1, 3
.AddNew
.Fields("IMAGE") = Stm.Read
.Update
End With
rs.Close
Stm.Close
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub
'从数据库中读取图像文件
Sub ReadFile()
Dim Stm As New ADODB.Stream
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCnn As String
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & _
App.Path & "\DB1.mdb"
Cnn.Open strCnn
rs.Open "SELECT IMAGE FROM TABLE1 WHERE ID = 18", Cnn, adOpenKeyset, adLockReadOnly
'保存到文件
With Stm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write rs("IMAGE")
.SaveToFile App.Path + "\Image2.bmp"
End With
'显示图片
Picture1.Picture = LoadPicture(App.Path + "\Image2.bmp")
rs.Close
Stm.Close
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub