JSP实现图片上传存入MySQL(jsp上传图片mysql)
Hello friends, I m John. Today I m going to share with you my experience of how to upload pictures to a MySQL database through JSP.
First, let s talk about the preparation work. We need to create a database table named `pic` in MySQL. The table structure is as follows:
` sql
CREATE TABLE pic(
id INT AUTO_INCREMENT NOT NULL,
data MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
) DEFAULT CHARSET = utf8;
Then we need to create a JSP page to upload the image, let"s call it `index.jsp`.
```jsp
Upload images
The next step is to create another JSP page to save the uploaded image to the database, let s name it `upload.jsp`.
`jsp
Upload images
%try{
// connect to mysql database through the specified url
Connection con = DriverManager.getConnection( jdbc:mysql://localhost:3306/test , root , root );
PreparedStatement pstmt = con.prepareStatement( insert into pic values(null,?) );
// type of data
pstmt.setBinaryStream(1, request.getInputStream());
pstmt.executeUpdate();
pstmt.close();
con.close();
%
% }catch(Exception e){
out.println(e);
%
Finally, after the two JSP pages have been created, we can upload the image to the MySQL database. We will open the `index.jsp` page in the browser, select an image, click the “upload” button, and the uploaded image will be written to the database table.
In this way, we can use JSP language to upload pictures to MySQL database. Although the code looks quite complicated, in fact, by understanding its structure, we can use JSP as a convenient tool to implement this task quickly. I hope this tutorial can help more friends.
Thank you for your listening. See you next time!
我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题
本站部分文章参考或来源于网络,如有侵权请联系站长。
数据库远程运维 JSP实现图片上传存入MySQL(jsp上传图片mysql)
相关文章
- 文件MySQL删除文件的强制策略(mysql强制删除)
- 大写MySQL:建立最佳数据库应用(mysql首字母)
- MySQL操作:执行SQL语句(mysql执行sql语句)
- MySQL教程:快速开始免费下载(mysql教程下载)
- 使用jsp构建MySQL连接(jsp与mysql连接)
- MySQL批量查询技巧实战(mysql批量查询)
- JSP连接MySQL实现登录功能(jsp登录mysql)
- MySQL远程登录配置:简单步骤轻松上手(mysql配置远程登录)
- MySQL中的二进制数据存储技术(mysql二进制数据)
- 函数MySQL的Length函数使用指南(mysql的length)
- MySQL加入服务:快速安装步骤(mysql添加到服务)
- 里如何在本地安装MySQL?(mysql装在哪)
- 快速高效的统计数量方法——使用 MySQL(统计数量mysql)
- MySQL数据库:遭遇被锁窘境(mysql 数据库被锁)
- MySQL解压缩安装过程及必要注意事项(mysql解压缩安装)
- MySQL中的Dump包备份数据库的解决方案(mysql中dump包)
- 使用cmd创建MySQL账户的步骤(cmd创建mysql账户)
- MySQL下载JSP学习JSP编程的必备数据库工具(mysql下载jsp)
- 解决MySQL上传速度缓慢问题的有效方法(mysql上传速度很慢)
- 使用MySQL上传本地文件 快速方便的数据库文件传输方式(mysql 上传本地文件)
- MySQL上传服务器时出现乱码问题原因和解决方法(mysql上传服务器乱码)
- MySQL 数据库如何处理上传日期(mysql 上传日期)
- 高效易用的方法MySQL大数据上传(mysql上传大数据)
- MySQL轻松上传到OSS,高效存储管理(mysql上传oss)
- 使用MySQL上传CSV文件的简便方法(mysql上传csv)
- 如何解决MySQL上传0的问题(mysql上传0%)