The following articles mainly describe how MySQL operates blob. If you are puzzled by the actual operations on blob in MySQL, you can use the following articles to understand the actual application and functions. The following is a detailed description of the article. I hope you will gain some benefits after browsing the following content. Jsp (preferred for SUN Enterprise Applications) + MySQL (matching with PHP)
The following articles mainly describe how MySQL operates blob. If you are puzzled by the actual operations on blob in MySQL, you can use the following articles to understand the actual application and functions. The following is a detailed description of the article. I hope you will gain some benefits after browsing the following content. Jsp (preferred for SUN Enterprise Applications) + MySQL (matching with PHP)
The following articles mainly describe how MySQL operates blob. If you are puzzled by the actual operations on blob in MySQL, you can use the following articles to understand the actual application and functions. The following is a detailed description of the article. I hope you will gain some benefits after browsing the following content.
Jsp (preferred for SUN Enterprise Applications) + MySQL (best combination with PHP) Remember to use the longblob type of MySQL (best combination with PHP) to store the default MySQL operation blob size.
Database field: id (char) pic (longblob)
Please indicate the source for reprinting. At this time, my cooperation with my confidant has been completed.
When operating blob fields, a null value must be removed first. It is troublesome to query blob. Using prepareStatment does not need to be so troublesome. Haha
Postblob. heml page
-
-
-
-
- Untitled document
-
-
-
-
-
-
- Testblob. jsp (preferred for SUN Enterprise applications)
- <% @ Page contentType = "text/html; charset = gb2312" %>
- <% @ Page import = "java. SQL. *" %>
- <% @ Page import = "java. util. *" %>
- <% @ Page import = "java. text. *" %>
- <% @ Page import = "java. io. *" %>
-
-
-
- Untitled document
-
-
- <%
- String id = request. getParameter ("id ");
- String file = request. getParameter ("file ");
- Out. print (id );
- Out. print (file );
- FileInputStream str = new FileInputStream (file );
- Out. print (str. available ());
- Java. SQL. Connection conn;
- Java. lang. String strConn;
- Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
- Conn = java. SQL. DriverManager. getConnection ("jdbc: MySQL (the best combination with PHP): // localhost/test", "root ","");
- String SQL = "insert into test (id, pic) values (?,?) ";
- PreparedStatement pstmt = conn. prepareStatement (SQL );
- Pstmt. setString (1, id );
- Pstmt. setBinaryStream (2, str, str. available ());
- Pstmt.exe cute ();
- Out. println ("Success, You Have Insert an Image Successfully ");
- Pstmt. close ();
- %>
- View images
- Return
-
-
- Readblob. jsp (preferred for SUN Enterprise applications)
- <% @ Page contentType = "text/html; charset = gb2312" %>
- <% @ Page import = "java. SQL. *, javax. SQL. *" %>
- <% @ Page import = "java. util. *" %>
- <% @ Page import = "java. text. *" %>
- <% @ Page import = "java. io. *" %>
-
-
-
-
- Untitled document
-
-
- <%
- Java. SQL. Connection conn;
- ResultSet rs = null;
- Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
- Conn = java. SQL. DriverManager. getConnection ("jdbc: MySQL (the best combination with PHP): // localhost/test", "root ","");
- Statement stmt = conn. createStatement ();
- Rs1_stmt.exe cuteQuery ("select * from test where id = '1 '");
- If (rs. next ())
- {
- Blob B = rs. getBlob ("pic ");
- Int size = (int) B. length ();
- Out. print (size );
- InputStream in = B. getBinaryStream ();
- Byte [] by = new byte [size];
- Response. setContentType ("image/jpeg ");
- ServletOutputStream sos = response. getOutputStream ();
- Int bytesRead = 0;
- While (bytesRead = in. read ())! =-1 ){
- Sos. write (by, 0, bytesRead );
- }
- In. close ();
- Sos. flush ();
- }
- %>
-
-
Note: When sos. write (by, 0, bytesRead); is used, the content of inputstream is output in a new page,
If there is other content to output on this page, you only need to change the above method to bytesRead = in. read ());
Use the out. print (new String (by) method to output the result. Note that the by. toString () method cannot be used here. This method returns the memory address of the content to be output. MySQL (the best combination with PHP) has the MySQL operation blob textarea type which is 66536 in size. It is enough to put something small. Haha, however, as digital pic grows, longblob can only be used.