如何使用Java将用户提供的图像保存到数据库 [英] How to save images provided by a user to a database using Java

查看:101
本文介绍了如何使用Java将用户提供的图像保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在计划如何编写一个GUI Java应用程序,该应用程序向用户显示一个表单以添加有关他们自己的信息。我想包括的一件事是用户可以向表单添加图片。提交后,图片和其余信息将被保存到数据库中。作为Java的新手,我希望获得一些指导性链接或有关如何完成此操作的提示。我当时想将表中的一栏设置为 BLOB类型,然后将其保存到表中,但这只是黑暗中的一枪。我真的不知道列类型应该是什么(字节,blob,ect ...),或者如何编码,以便将图片保存到我的数据库中以便以后显示。我想我的问题是如何从表单获取图片并将其保存到数据库。我将尝试使用eclipse进行此操作,但仍不确定我将对数据库使用什么。抱歉,引起您的困惑!

I am planning how I to write a GUI Java application that displays a form to the user to add information about themselves. One of the things I want to include is the ability for the user to add a picture to the form. Upon submission the picture and the rest of the info will then be saved to a database. Being new to java I was hoping for some instructional Links or tips as to how to accomplish this. I was thinking of setting one of my columns in my table as a 'BLOB' type and then saving them to it, but that is just a shot in the dark. I really don't know what the column type should be (byte, blob, ect...), or how to code so that the picture will be saved to my database for display later. I guess my question is how to get and save a picture to a database from a form. I am going to attempt this using eclipse, and am still unsure what I will use for the database. Sorry about any confusion, and thanks for reading!!

提请

推荐答案

<如果您真的想将图像存储在数据库中,BLOB似乎是保存图像的列的最适合的类型。

If you really want to store your image in the database, BLOB seems to be the most adapted type for the column holding the image.

但是恕我直言,这些类型的文件不必存储在数据库中。只需将它们存储在目录中的某个位置,然后将图像名称(或生成的ID)保留在数据库中即可。

But IMHO, those types of files do not have to be stored in a database. Just store them somewhere in a directory and just keep the image names (or a generated id) in your database.

这篇关于如何使用Java将用户提供的图像保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆