Hướng dẫn how can we retrieve blob data from mysql database using jsp? - làm cách nào chúng tôi có thể truy xuất dữ liệu blob từ cơ sở dữ liệu mysql bằng jsp?
Display Blob(Image) from Mysql table using JSPIn this section, we will display blob data(image) from Mysql database table using JSP code. Show
In this section, we will display blob data(image) from Mysql database table using JSP code. Display Blob(Image) from Mysql table using JSPIn this section, we will display blob data(image) from Mysql database table using JSP code. A Blob stores a binary large object in the database table's row. Blob object contains a logical pointer which points to the Blob data, data is not directly stored in the row of the database table. Blob object is valid for the duration of the transaction. The "getBlob()" and "setBlob()" method of "ResultSet" ,"CallableStatement", and "PreparedStatement" interface , is used for accessing Blob value. The Method defined in " java.sql.Blob " interface is as follows-- Return Type
Method Description InputStream getBinaryStream()
Retrieves the blob value designated byte[] getBytes(long pos, int length) Retrieve all or part of the blob value that long length() Returns the no of bytes in the Blob OutputStream setBinaryStream(long pos) Retrieves a stream that can be used int setBytes(long pos, byte[] bytes) Write the given array of bytes to the Blob void & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cắt ngắn (len dài) & nbsp; & nbsp; & nbsp; ; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; đối tượng đại diện cho là len byte trong Len truncate(long len) Truncates the blob value that this blob Kiểu dữ liệu Blob có thể được phân loại thành bốn loại--
THÍ DỤ : displayblob.jsp <%@ pageImport = "java.sql.*"%> pageImport = "java.io.*"%> import="java.sql.*"%><%@ page import="java.io.*"%><% Blob image = null;pageImport = "java.sql.*"%> pageImport = "java.io.*"%> null; byte[ ] imgData = null ;Kết nối con = null;Câu lệnh stmt = null; try {Resultset rs = "com.mysql.jdbc.Driver");Class.forname ( "jdbc:mysql://192.168.10.13:3306/ankdb","root","root");con = DriverManager.getConnection ( stmt = con.CreateStatement (); rs = stmt.executequery ( hình ảnh = rs.getBlob (1); int)image.length());imgdata = Image.getBytes (1, ( else {out.println( "Display Blob Example");out.println( "image not found for given id>"); return;} // display the imageresponse.setContentType( "image/gif");} o.write(imgData); o.flush(); o.close(); imgdata = Image.getBytes (1, ( catch (Exception e) {out.println( out.println( "Image Display Error=" + e.getMessage()); return;imgdata = Image.getBytes (1, ( finally { try {rs.close(); stmt.close(); con.close(); imgdata = Image.getBytes (1, ( catch (SQLException e) {e.printStackTrace(); } } %>} OutputStream o = respons.getOutputStream (); Insert Blob(Image) in Mysql table using JSP Đầu ra: Làm thế nào để truy xuất hình ảnh blob từ cơ sở dữ liệu MySQL trong JSP?displayblob.jsp.. . . Kết nối con = null ;. Câu lệnh stmt = null ;. Class.forName("com.mysql.jdbc.Driver");. con = DriverManager.GetConnection ("JDBC: mysql: //192.168.10.13: 3306/ankdb", "root", "root"); .... rs = stmt.executeQuery ("Chọn hình ảnh từ inimage trong đó id = '6'") ;. Làm cách nào để nhận dữ liệu blob từ cơ sở dữ liệu MySQL?Truy xuất hình ảnh và tệp được lưu trữ dưới dạng blob từ bảng MySQL bằng Python.. Cài đặt Python đầu nối MySQL bằng PIP .. Thứ hai, thiết lập kết nối cơ sở dữ liệu MySQL trong Python .. Sau đó, xác định truy vấn chọn để tìm nạp các giá trị cột Blob từ bảng cơ sở dữ liệu .. Thực hiện truy vấn chọn bằng con trỏ.execute (). Sử dụng con trỏ .. Làm cách nào để nhận hình ảnh blob từ cơ sở dữ liệu trong mysql?Để hiển thị hình ảnh Blob cho trình duyệt, hãy tạo tệp PHP và thực hiện các hoạt động sau ... Nhận dữ liệu hình ảnh được lưu trữ với trường Blob MySQL trong cơ sở dữ liệu .. Đặt loại nội dung là hình ảnh (hình ảnh/jpg, hình ảnh/gif, trên) bằng tiêu đề PHP () .. In dữ liệu blob hình ảnh trong PHP .. Làm thế nào chúng ta có thể lấy dữ liệu từ cơ sở dữ liệu trong JSP?Chọn một dữ liệu cụ thể từ cơ sở dữ liệu trong JSP.. Bước 1: Tạo một dự án mới.Trong bước này, chúng tôi chọn tùy chọn dự án mới từ menu tệp .. Bước 2: Chọn Dự án.Trong bước này, chúng tôi chọn ứng dụng web từ tùy chọn Java Web và sau đó nhấp vào nút tiếp theo .. Bước 3: Tên và vị trí .. |