Export table from DB to an XML file with Java - java

I need to read every row of a particular table stored in a mysql DB, then i have to write an xml file extracted from each row.
Which is the best practice for obtaining this target? I should use some java libraries, but i don't know how to choose the exact ones.

look at this:
http://examples.javacodegeeks.com/core-java/xml/bind/jaxb-marshal-example/
From the DB if you use an ORM like hibernate or other you will get your rows as objects and then you can transforme them using JAXB.

Related

loading a word2vec model into a Mysql database

I have a word2vec model stored in text file as
also -0.036738 -0.062687 -0.104392 -0.178325 0.010501 0.049380....
one -0.089568 -0.191083 0.038558 0.156755 -0.037399 -0.013798....
The size of the text file is more than 8GB.
I want to read this file into mysql database using the first word as key (in a column) and the rest of the line as another column. Is it possible to do so without reading each line and splitting it?
I went through some related questions but it didn't match what I want.
How to read a file and add its content to database?
read text file content and insert it into a mysql database
you can do it by:
making a simple for loop that iterates over the records on the model
aggregating about 100 records on an array
using mysql bulk insert feature to insert 100s of records at once
use a fast language like go if you can.
This thing you are trying to do, it's very possible, let me know if you need code for this.

Download completeDB as CSV

I have a complicated database that deals with many tables. Some of them are related as in the following table:
Now the requirement is to collect all the corresponding rows in all of the tables from one identifiable field in the entry level table, and download it as CSV.
What comes to my mind is a simple iterative strategy and storing relevant data. But this seems inefficient since the query goes too long and have to iterate it a few times to get everything I need.
Is there any better approach to this problem? I'm using Jsp-Java-spring-MySQL.
I would suggest using a command line of mysql or mysqldump utility(fastest approach) and you can also use a DB tool like Toad or mysql workbench. See if these posts helps :
mysqlworkbench
mysqldump

How to Use SELECT Query on Xml using java

I am having an xml file which contains data from different tables.
These tables are linked to each other.
I want to access Records from the xml.
Can i write SQL select query on Xml file.
No, you cannot use SQL for XML files. Either move the data to a relational store or use a hierarchical query language.
All you can expect after such a vague question is a bunch of random keywords (like XQuery, eXist, XPath, Oracle XML Db, MarkLogic, Jaxen). Probably none of them is relevant to whatever problem you might have at hand.

How to generate DDL for a table-column in any database using java?

My requirement is I want to diff two database which can be any database ,for now considering 3 database Oracle,MySQL,PostGresql and suppose if any of two database has a common schema with common table name,but lets say those two tables are different. The tables can have different column or different column data type etc.How can I generate a diff query which on can be executed on a particular DB to make both of them equal. I was going through schemacrawler(http://schemacrawler.sourceforge.net/how-to.html) but didint got any API which can be used to generated DDL. Though the tool is good to crawl through schema and table -columns etc,but how can I generate DDL in java so that I can make both database equal. I can get database meta data using java api but how can I use it to generate appropriate DDL to make both database equal,if possible please paste sample code snippet.
We use tool called DBSolo to compare schema and generate diff sql. It is invoked via scripts, not using java code though.
I used liquibase in my personal work. The example given are in script, it will be trivial to integrate using java.

How do I write and read data in txt file in the form of rows and columns?

How do I write and read data in txt file in the form of rows and columns? Also, how do I store many files like this in a folder for a particular name? The idea is just like a Table for a particular person who has many rows and columns.
You'll want to look into comma-separated value files.
In addition to Jeremy's post
Use opencsv to create the csv file
Use CsvJdbc to use JDBC to query against those files. This makes the future transition to DB in future and you will be working with a known API for searching against the file

Categories