導航:首頁 > 編程大全 > java如何從資料庫里取圖片

java如何從資料庫里取圖片

發布時間:2025-08-08 17:12:26

Ⅰ 誰有資料庫中存的是圖片路徑,然後jsp頁面顯示圖片出來

1、准備要顯示的圖片,並創建一個最簡單的jsp頁面,運行起來。

java中怎麼獲取mysql資料庫的數據

用JDBC連接資料庫,然後用sql語句。要導入的驅動包。
import java.sql.*;

public class TestMySql {
static Connection con = null; // 聲明Connection對象
static Statement sql = null;
static ResultSet res = null;

public static void main(String[] args) {
TestMySql c = new TestMySql();
con = c.getConnection();
try {
sql = con.createStatement();
res = sql.executeQuery("select * from dept");
//sql語句,我資料庫里有張dept表

while (res.next()) {//輸出結果
System.out.print(res.getString(1) + "<——>");
System.out.print(res.getString(2) + "<——>");
System.out.print(res.getString(3) );
System.out.println();
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (res != null) {
res.close();
res =null;
}
if (sql != null) {
sql.close();
sql =null;
}
if (con != null) {
con.close();
con =null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}

}

public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
// 載入oracleJDBC驅動
System.out.println("資料庫驅動載入成功");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {// 通過訪問資料庫的URL獲取資料庫連接對象
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydata", "root", "qwer1234");
//mydata為mysql名字

System.out.println("資料庫連接成功");
} catch (SQLException e) {
e.printStackTrace();
}
return con; // 按方法要求返回一個Connection對象
}

}

閱讀全文

與java如何從資料庫里取圖片相關的資料

熱點內容
為什麼安卓手機鎖屏app就掉線 瀏覽:365
java執行curl命令 瀏覽:783
哪些網站可以上傳超大視頻 瀏覽:960
大神級別的網路小說有哪些 瀏覽:915
backucup是哪個文件夾 瀏覽:443
編程命令框是什麼 瀏覽:380
sql文件的路徑 瀏覽:137
閑魚app上怎麼賣舊書 瀏覽:271
電腦無線網熱點在哪裡設置密碼 瀏覽:807
從qq郵箱怎麼發送文件在哪裡設置 瀏覽:712
word座簽模板 瀏覽:234
怎麼導出k線數據到excel 瀏覽:409
pdf文件怎麼編輯對號 瀏覽:164
無法復制伺服器文件路徑 瀏覽:310
什麼軟體可以把腳本弄成app 瀏覽:280
微信公眾號有哪些交友app 瀏覽:109
css盒工具 瀏覽:617
用什麼電腦編程好 瀏覽:267
ptr編程什麼意思 瀏覽:450
粉筆app課件怎麼弄 瀏覽:225

友情鏈接