java讀取資料庫的圖片
① java怎樣把圖片保存到資料庫然後讀出來在html中顯示
一般是將圖片本體存放到OSS,圖片的路徑存放到資料庫,然後jsp中獲取的是他的路徑
然後用<img src="OSS的鏈接/"+你資料庫的圖片路徑> 你可以用本地圖片試試 將圖片本體存放在你的E盤/image下面 然後你存入資料庫的是你的圖片名 然後將圖片上傳到本地 然後使用<img src='E盤/image'+資料庫裡面的圖片名> 就可以顯示了 你可以試試
② JAVA怎麼把圖片從資料庫中調用出來
1 一半圖片都是把路徑存放在資料庫的攜鍵彎 到時候取出路徑就可以了辯悶
2 在資料庫有blob格式可以存放圖片 以二進制流的方式取出來
<% String zjbm = CheckParam(request.getParameter("zjbm"),""); String zpsql = "select zp from tjjryxxx where sfzh = '"+zjbm+"'"; out.clear(); response.setContentType("image/jpeg"亮判); response.setHeader("Content-Transfer-Encoding","base64"); Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; Blob blob =null; byte[] data = null; try{ connection =getConn(); ps = connection.prepareStatement(zpSql); rs = ps.executeQuery(); while(rs.next()){ blob = (Blob)rs.getBlob("zp"); long nlen = blob.length(); int nsize = (int) nlen; data = blob.getBytes(1,nsize); OutputStream out1 = response.getOutputStream(); BufferedOutputStream bos =null; bos = new BufferedOutputStream(out1); bos.write(data,0,data.length); bos.close(); rs.close(); } }catch(Exception e){ e.printStackTrace(); } %>
③ javaweb怎麼在資料庫中讀取圖片
一般像圖片,聲音,視頻這樣的在東西不適合直接存入資料庫中,因為這樣會影響系統的性能,而是存在項目的某個文件中,然後存它們的路徑就可以 了,讀取圖片也是讀取路徑
④ 在JAVA中如何將圖片從資料庫讀取到頁面上
你只要開啟一個輸出流將從資料庫取出來的圖片(這個時候肯定是二進制數據是吧),寫出來就行了.
然後在調用圖片的地方調用相應的方法就可以輸出了.
⑤ Java怎樣讀取資料庫中的二進制圖片並下載到本地磁碟
/**
* Created by IntelliJ IDEA.
* User: ljt
* Date: 2003-3-31
* Time: 18:51:38
* To change this template use Options | File Templates.
*/
import oracle.jdbc.driver.OraclePreparedStatement;
import oracle.jdbc.driver.OracleResultSet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Clob;
public class TestOpenDoc {
public OracleResultSet ors = null; //**這里rs一定要用Oracle提供的
public OraclePreparedStatement opst = null; //**PreparedStatement用
public Connection conn = null;
public Statement stmt = null;
public TestOpenDoc() {
}
public boolean getConnect() {
//這是我的資料庫所在
String serverName = "prosrv";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@" + serverName + ":1521:BOHDATA";
conn = DriverManager.getConnection(url, "appuser", "appuser");
}
catch (Exception e) {
System.out.println(e);
return false;
}
return true;
}
public static void main(String[] args) {
TestOpenDoc test = new TestOpenDoc();
if (!test.getConnect()) {
System.out.println("資料庫連結錯誤");
return ;
}
try{
test.conn.setAutoCommit(false);
byte a[] = null; //**將測試文件test.doc讀入此位元組數組
java.io.FileInputStream fin = null;
java.io.FileOutputStream fout = null;
//Oracle提供的
try {
java.io.File f1 = new java.io.File("c:/test.doc");
java.io.File f2 = new java.io.File("d:/testout.doc"); //**從BLOB讀出的信息寫
//入該文 件,和源文件對比測試用
fin = new java.io.FileInputStream(f1);
fout = new java.io.FileOutputStream(f2);
int flength = (int) f1.length(); //**讀入文件的位元組長度
System.out.println("file length::" + flength);
a = new byte[flength];
int i = 0;
int itotal = 0;
//* 將文件讀入位元組數組
for (; itotal < flength; itotal = i + itotal) {
i = fin.read(a, itotal, flength - itotal);
}
fin.close();
System.out.println("read itotal::" + itotal);
//**注意Oracle的 BLOB一定要用EMPTY_BLOB()初始化
String mysql =
"insert into filelist (FileName,FileSize,FileBody) values (?,?,EMPTY_BLOB())";
OraclePreparedStatement opst = (OraclePreparedStatement) test.conn.
prepareStatement(mysql);
opst.setString(1, "wordtemplate2");
opst.setInt(2, flength);
opst.executeUpdate();
opst.clearParameters();
// /**插入其它數據後,定位BLOB欄位
mysql = "select filebody from filelist where filename=?";
opst = (OraclePreparedStatement) test.conn.prepareStatement(mysql);
opst.setString(1, "wordtemplate2");
OracleResultSet ors = (OracleResultSet) opst.executeQuery();
if (ors.next()) {
oracle.sql.BLOB blob = ors.getBLOB(1); //**得到BLOB欄位
int j = blob.putBytes(1, a); //**將位元組數組寫入BLOB欄位
System.out.println("j:" + j);
test.conn.commit();
ors.close();
Clob clob;
clob = ors.getClob("");
String str;
str = clob.toString();
str = clob.getSubString(0L,(int)clob.length());
System.out.println(str);
}
System.out.println("insert into ok");
byte b[] = null; //**保存從BLOB讀出的位元組
opst.clearParameters();
mysql = "select filebody from filelist where filename=?";
opst = (OraclePreparedStatement) test.conn.
prepareStatement(mysql);
opst.setString(1, "wordtemplate2");
ors = (OracleResultSet) opst.executeQuery();
if (ors.next()) {
oracle.sql.BLOB blob2 = ors.getBLOB(1);
System.out.println("blob2 length:" + blob2.length());
b = blob2.getBytes(1, flength); //**從BLOB取出位元組流數據
System.out.println("b length::" + b.length);
test.conn.commit();
}
ors.close();
// 將從BLOB讀出的位元組寫入文件
fout.write(b, 0, b.length);
fout.close();
System.out.println("write itotal::" + b.length);
}
catch (Exception e) {
System.out.println("errror :" + e.toString());
e.printStackTrace();
}
finally { //**關閉所有數據聯接
test.conn.commit();
}
}
catch(Exception e){
System.out.println(e);
}
}
}
⑥ java 資料庫讀取圖片出來全部是1KB
public static void readDB2Image() {
String targetPath = "D:/123/1.png";
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBUtil.getConn();
String sql = "select * from map where id =?";
ps = conn.prepareStatement(sql);
ps.setInt(1, 1);
rs = ps.executeQuery();
while (rs.next()) {
InputStream in = rs.getBinaryStream("photo");
ImageUtil.readBin2Image(in, targetPath);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeConn(conn);
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
⑦ java讀取照片保存到達夢資料庫
存儲圖片是後端伺服器比較基礎的功能,一般來說,圖片可以存儲在伺服器的文件系統中,然後資料庫中只需要存儲url就可以了。另外一種辦法是,將圖片通過Base64編碼後存儲到資料庫中,資料庫中存儲圖片的base64編碼的二進制可以使用TEXT(mysql)類型。
⑧ JAVA 讀取 資料庫中的圖片顯示到頁面
你說你只想存ID到資料庫中,那你就專門用個文件夾存放圖片,ID值就是圖片文件名字!從資料庫得到ID後,就在<IMG SRE="這里寫上絕對路徑"+ID+".jpg"/>
⑨ 在java中怎麼獲取資料庫中已經保存的圖片
如果要存資料庫的話,資料庫存圖片欄位用blob形式的(照片:zp為例)。
而且不能直接存,在存之前zp欄位先插入一個empty.BLOB(),
然後select ZP from 表 for update。再用輸入流的形式寫進去。
// 先檢索出來欄位,必須使用oracle的類:oracle.sql.BLOB
oracle.sql.BLOB blob = null;
if (rs.next())
{
blob = (oracle.sql.BLOB) rs.getBlob("ZP");
// 到資料庫的輸出流
⑩ java讀取資料庫中圖片的地址,然後再顯示在jLabel框中,但是運行後沒有載入圖片,這是什麼原因,求解啊
Icon icon = new ImageIcon(Pic_address)應櫻山逗該改為Icon icon = new ImageIcon(Pic_address).getImage();你唯滾原來沒有去獲得圖片
好使記脊賣得給分啊