Difference between Oracle and MySQL when uploading images via SSH (struts2)

Source: Internet
Author: User

For example, after having suffered a lot of losses from Nn, I am determined to write this article. I would like to sum up the experience of uploading slice. The type may be incorrect. I believe everyone understands it. I just want to write down my ideas.

 

Previously, I used struts1.x to upload images. It used formfile to encapsulate the file parameters passed by the page, and struts2.x used file-type files, you can also encapsulate the filename and filecontenttype file types (it seems that this attribute is not the same as this one), encapsulate the data in the action, and then process it at the DaO layer, there is a difference here:

(Assume that the database field name is photo, the attribute name of the pojo object is photo, and the attribute name of the Action encapsulation file is photofile)

1: Oracle Database:

 

Pojo object attributes are set to blob type, and then use

Fileinputstream = new fileinputstream (photofile );

Hibernate. createblob (fileinputstream );

This method returns a blob type of data. In the hibernate ing file, <property name = "photo" column = "photo"/>. If there is a problem, add the type attribute and call gethibernatetemplate (). save.

 

 

2. MySQL database:

 

The attribute of pojo needs to be modified. The Blob type is not used here. The byte [] type is used instead,

 

Byte [] filebytes = NULL;

Fileinputstream = new fileinputstream (photofile );

Filebytes = new byte [fileinputstream. avaliable ()];

Fileinputstream. Read (filebytes );

Fileinputstream. Close ();

 

Save the image in binary format, and modify the hibernate ing file

<Property name = "photo" column = "photo" type = "binary"/> and then call the gethibernatetemplate. Save () method. Except for some, you do not need to modify it like Oracle. (At least I did. It succeeded ).

 

 

Note: struts has a size limit on File Upload. The default value seems to be a little larger than 2 MB (you can change the struts configuration), and MySQL does the same. If it is a large file, it is not recommended to store the data directly in the database. On the other hand, you must first modify the MySQL configuration file my. INI, add a max_allowed_packet (it looks like this, Google it), set the maximum allowed value to upload.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.