当前位置:首页 » 操作系统 » java读取数据库的图片

java读取数据库的图片

发布时间: 2023-05-24 15:38:20

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();你唯滚原来没有去获得图片

好使记脊卖得给分啊

热点内容
编译语言全家桶软件 发布:2025-04-22 17:02:29 浏览:387
javascriptdes加密 发布:2025-04-22 17:02:11 浏览:384
python线程参数 发布:2025-04-22 17:01:01 浏览:317
卫生员什么配置 发布:2025-04-22 17:00:02 浏览:219
苹果系统搭建服务器的软件 发布:2025-04-22 16:36:29 浏览:13
房车配置怎么选择 发布:2025-04-22 16:22:14 浏览:492
编程猫gb 发布:2025-04-22 16:22:13 浏览:632
密码加密php 发布:2025-04-22 16:07:09 浏览:582
imac存储空间为什么这么小 发布:2025-04-22 15:45:30 浏览:223
上传时速是0 发布:2025-04-22 15:37:49 浏览:568