将json文件转换成insert语句的sql文件
引入是要的maven依赖:
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
转换:
package com.iot.zjdy.exampl.test; import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter; /**
* Created by Yanwu 2018/2/8.
*/
public class JsonToSqlTest {
private static final String PATH = "C:\\demo\\file\\Cab_LN_FeaturesToJSON.json"; public static void main(String[] args) throws Exception {
System.out.println("========== JSON ---> 转换成 SQL 开始 ==========");
jsonToExcel();
System.out.println("========== JSON ---> 转换成 SQL 结束 ==========");
} private static void jsonToExcel() throws Exception {
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = (JsonObject) jsonParser.parse(new FileReader(PATH));
JsonElement features = jsonObject.get("features");
JsonArray asJsonArray = features.getAsJsonArray();
for (int i = 0; i < asJsonArray.size(); i++) {
JsonElement jsonElement = asJsonArray.get(i);
JsonObject featuresObj = jsonElement.getAsJsonObject();
JsonElement attributes = featuresObj.get("attributes");
JsonObject attributesObj = attributes.getAsJsonObject();
JsonElement swchName = attributesObj.get("swchName");
String nameStr = swchName.toString();
JsonElement geometry = featuresObj.get("geometry");
JsonObject geometryObj = geometry.getAsJsonObject();
JsonElement path = geometryObj.get("paths");
String pathStr = path.toString();
String replace = nameStr.replace("\"", "");
String sqlStr = "insert into poly_line (id, box_name, paths) values (" + i + ", '" + replace + "', '" + pathStr + "'); \r\n";
System.out.println(sqlStr);
File file = new File("C:\\demo\\file\\Cab_LN.sql");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file, true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(sqlStr);
bufferedWriter.close();
}
}
}
将json文件转换成insert语句的sql文件的更多相关文章
- PL/Sql快速执行 insert语句的.sql文件
当全是 insert语句的.sql文件太大时(insert 语句条数太大),直接打开执行sql文件,pl/sql会卡死. 这是可以用pl/sql的命令窗口来执行.sql文件,操作步骤如下: 1.新建命 ...
- 如何将md文件转换成带目录的html文件
配置环境node 去官网下一个node安装包,下一步下一步: 由于现在的node都自带npm,直接 npm install i5ting_toc 这样安装好了i5ting_toc这个包, 进入你实现准 ...
- net9:图片文件转换成二进制流存入SQL数据库,以及从数据库中读取二进制流输出文件
原文发布时间为:2008-08-10 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- sql server 数据库导出表里所有数据成insert 语句
有时候,我们想把数据库的某张表里的所有数据导入到另外一个数据库或另外一台计算机上的数据库,对于sql server有这样的一种方法 下面我以sql server 2008 R2,数据库是Northwi ...
- 将jar文件转换成exe可执行文件[转]
将jar文件转换成exe可执行文件: exe文件使用方便,而且还可以提高源码及资源的安全性,但同时也失去了java的初衷--跨平台性. 如果你坚持要转换成exe文件,请按以下方式进行: 利用exe4j ...
- JAVA将文件转换成byte数组(byte[])
/** * 将文件转换成byte数组 * @param filePath 文件File类 通过new File(文件路径) * @return byte数组 */ public static byte ...
- java转换unicode,筛选文件中的insert语句并把日期给转换为可以直接在数据库执行的语句
package com; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; impo ...
- json串转化成xml文件、xml文件转换成json串
1.json串转化成xml文件 p=[{"name":"tom","age":30,"sex":"男" ...
- MyBatis项目实战 快速将MySQL转换成Oracle语句
一.前言 因项目需求,小编要将项目从mysql迁移到oracle中 ~ 之前已经完成 数据迁移 (https://zhengqing.blog.csdn.net/article/details/103 ...
随机推荐
- BZOJ1777: [Usaco2010 Hol]rocks 石头木头
n<=10000的树,节点有初始石头数<=1000,进行这样的游戏:两人轮流行动,我先手,每次可以选一个节点(≠1)把不超过m<=1000个石头移到父亲,最后所有石头都在节点1,没法 ...
- hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131 ...
- js命名
JS变量名前加 _ 与 $ 的区别: 下划线一般当做私有属性, 业界会比较常用$开头作为框架.库的关键词前缀,目的是避免命名冲突
- CodeForces 592D Super M
先把没用的边去掉,求出包含m个点的最小树.然后求出最小树的直径就可以得到答案了. #include <cstdio> #include <cstring> #include & ...
- Google的Guava类库简介(转)
说明:信息虽然有点旧,至少可以先了解个大概. Guava是一个Google的基于Java的类库集合的扩展项目,包括collections, caching, primitives support, c ...
- css实现文字渐变
css文件渐变虽然兼容性比较差,但是用在移动端和chrome中还是没有问题的. 实现文件渐变的方法有两种 1. 使用 background 的属性 2. 使用 mask 属性 方式一. <!DO ...
- java的计时:毫秒、纳秒
System.currentTimeMillis()获取毫秒值,但是其精度依赖操作系统 想实现较为精确的毫秒,可以采用 System.nanoTime()/1000000L System.nanoTi ...
- [Bash] View Files and Folders in Bash
Sometimes when working at the command line, it can be handy to view a file’s contents right in the t ...
- B-Tree 索引和 Hash 索引的对照
对于 B-tree 和 hash 数据结构的理解可以有助于预測不同存储引擎下使用不同索引的查询性能的差异.尤其是那些同意你选择 B-tree 或者 hash 索引的内存存储引擎. B-Tree 索引的 ...
- Office WORD里面打字,后面的字自动被删除怎么办
word或其他编辑器里打字以后其后面的字就被自动删除了-解决方案 2011-09-26 14:52:09| 分类: 电脑维护|字号 订阅 解决方法: 再按一下 Insert键 就OK啦 今天有 ...