Solved

MySQL: Upload a JSON file into a table programmatically

Posted on 2016-08-08
8
25 Views
Last Modified: 2016-09-26
Hi
Does anymore know about a technique, a tool or set of commands to load a JSON file into a mysql table. Please, note fields will match with the JSON structure.
I know I can do it in MySQL Workbench, but I want to automate the process.

Thanks
0
Comment
Question by:Omer-Pitou
  • 4
  • 3
8 Comments
 
LVL 8

Assisted Solution

by:James Bilous
James Bilous earned 500 total points
ID: 41747563
This is a common task called data "marshalling". Essentially, what you'll want to do is write a java program that takes the JSON from in memory, connects to a database using JDBC (or some other database connection API), and loops through your JSON while inserting the data as rows in your database. Here is a good article on the process:

http://www.codeproject.com/Articles/1087995/Inserting-JSON-Text-into-SQL-Server-Table
0
 

Author Comment

by:Omer-Pitou
ID: 41747774
Thanks James,
What I am avoiding is to loop through these rows.
I think I will convert it to CSV, and load it with MySQL LOAD INFILE
0
 
LVL 8

Expert Comment

by:James Bilous
ID: 41747794
In that case there are online converters that will get you from json to csv that you can fin pretty readily via Google search.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:Omer-Pitou
ID: 41747800
Do you know any 3rd party library that I can embed into the app
0
 
LVL 8

Expert Comment

by:James Bilous
ID: 41747818
What exactly are you doing? You didn't really give a lot of context to your problem. You're making an android app that receives JSON and you want to put it into a database by converting it to CSV first? This seems to be the most round about and difficult way to do this. Why not just use all the tools and APIs available from the Android Developmen toolkit that were made for this exact purpose?
0
 

Author Comment

by:Omer-Pitou
ID: 41747831
I am not developing an Android app.
It is a SE app which will in a local network.
Some of the data need to be transferred to a remote database (web server) to serve the web dashboard application. This will be done through a web service.
0
 
LVL 8

Accepted Solution

by:
James Bilous earned 500 total points
ID: 41747848
I would use the org.json.CDL library:


https://github.com/stleary/JSON-java
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
update joined tables 2 45
web application structure 18 76
by zero exception 10 39
Problem to Alipay 10 21
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question