简体   繁体   English

如何使用Struts2在Blob类型列中的sql中保存图像?

[英]how to save image in my sql in blob type columns with Struts2?

I have a Struts2 jsp page their i am sending one image, Temporary file path is comming to my java class after form submission but i do not know how can to save that path in db by changing it to Blob type.. Please consider this image columns is of blob type in my database table.. 我有一个Struts2 jsp页面,我正在发送一个图像,表单提交后,临时文件路径正在传入我的java类,但是我不知道如何通过将其更改为Blob类型来在DB中保存该路径。我的数据库表中的列是Blob类型。

Here is the output what am getting in my Javaclass after the form submission: 提交表单后,这是我的Java类中得到的输出:

My image path: 我的图片路径:

F:\\Documents and Settings\\software.netbeans\\7.0\\apache-tomcat-7.0.11_base\\work\\Catalina\\localhost\\AIGSA\\upload__214d4f3e_136e8b74d9c__7fff_00000021.tmp 105542 F:\\ Documents and Settings \\ software.netbeans \\ 7.0 \\ apache-tomcat-7.0.11_base \\ work \\ Catalina \\ localhost \\ AIGSA \\ upload__214d4f3e_136e8b74d9c__7fff_00000021.tmp 105542

filenames: * Winter.jpg 文件名:* Winter.jpg

Code: 码:

for (File u: repImage) 
{
    System.out.println("*** "+u+"\t"+u.length());
}

int saveToDb= mo.addMembers(memberName, repImage);

How can I send my form Image to this {repImage Name , so that it will be easy to save it so my db 如何将表单图像发送到此{repImage Name ,这样将很容易保存它,因此我的数据库

不确定,请尝试:

int saveToDb= mo.addMembers( memberName, repImage.getBytes() );

If I understand your question properly, you want to store the binary data in your database. 如果我正确理解了您的问题,则希望将二进制数据存储在数据库中。 I'd say this is a bad idea in the first place for multiple reasons. 我说这首先是个坏主意,原因有很多。 A better method would be to reference a relative path that you can then use in your web application or the file system directly. 更好的方法是引用一个相对路径,然后您可以在Web应用程序或文件系统中直接使用该相对路径。 Better yet, just store the reference to the location in Amazon/S3 where you want to save it/use it. 更好的是,只需将对引用的引用存储在您要保存/使用的Amazon / S3中。

Regardless, to answer your question you would want to use ByteArrayOutputStream . 无论如何,要回答您的问题,您都想使用ByteArrayOutputStream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM