JMeter是否可以在mysql数据库表中上传文件? [英] Is it possible to upload file in mysql database table by JMeter?

查看:114
本文介绍了JMeter是否可以在mysql数据库表中上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JMeter的新用户.我已经知道如何使用jmeter进行测试.现在我的问题是,是否可以通过JMeter将文件上传到mysql表中?

I am new JMeter user.I already know how to use jmeter for testing.Now my question is,Is it possible to upload file in mysql table by JMeter?

推荐答案

如果我正确使用了您的用例,则需要在MySQL BLOB或CLOB字段中插入一个文件.它可以通过JMeter完成.

If I'm correctly getting your use case - you need to insert a file into MySQL BLOB or CLOB field. It's doable via JMeter.

选项1:

您是否尝试过JMeter JDBC请求采样器Prepared Update Statement选项?它应该能够为您解决问题.

Have you tried Prepared Update Statement option of JMeter JDBC Request Sampler? It should be able to do the trick for you.

选项2

如果需要更大的灵活性,可以通过Beanshell 扩展.您需要删除 MySQL JDBC Connector 并将其放在JMeter类路径中的任何位置(通常是它是扩展jar的/lib/ext文件夹).

If you need more flexibility JMeter can be extended via Beanshell. All you need is to drop MySQL JDBC Connector and drop it anywhere in JMeter classpath (usually it's /lib/ext folder for extension jars).

完成后,您可以建立MySQL连接并将文件插入MySQL数据库.示例代码如下:

Once done you can establish MySQL connection and insert your file into MySQL database. Example code is below:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://host:port/databasename?user=databaseuser&password=databasepassword");
PreparedStatement preparedStatement = connect.prepareStatement("INSERT INTO MY_TABLE(id, blob_col) VALUES(1, LOAD_FILE('/full/path/to/file/myfile.png')");
preparedStatement.executeUpdate();
connect.close();

这篇关于JMeter是否可以在mysql数据库表中上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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