Is it possible to upload file in mysql database table by JMeter?(是否可以通过 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
如果你需要更多的灵活性 JMeter 可以通过 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 数据库表中上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以通过 JMeter 在 mysql 数据库表中上传文件?
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
