導航:首頁 > 編程大全 > 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如何從資料庫里取圖片相關的資料

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接