有时从网上界面中获取的数值是json格式的,需要存储到mysql数据库中,这时可以利用java的代码实现
json的样例:
//保存的文件名称为test.json
{
"rows":[
{
"number": "001",
"name": "烟感",
"floor": "3",
"position": "3层南竖井",
"starttime":"2019-08-09 15:00:30"
},
{
"number": "002",
"name": "烟感",
"floor": "3",
"position": "3层南电梯厅",
"starttime":"2019-08-08 1:10:30"
}]
}
java代码如下,需要用到一个解析json的jar包,gson-2.8.0.jar:
public class TestJsonDateToMysql {
private static final String url = "jdbc:mysql://localhost:3306/sys?useUnicode=true&characterEncoding=utf-8&useSSL=