Package edu.wisc.game.tools
Class ExportTable
java.lang.Object
edu.wisc.game.tools.ExportTable
This is a substitute for something like this:
select * into outfile '/var/lib/mysql-files/tmp-PlayerInfo.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM game.PlayerInfo;It is to be used on machines where the MySQL server is not set up with permissions to write to any directory (i.e. @@secure_file_priv is NULL).
Unlike most of other database-connecting tools, this class uses the plain JDBC Connection, rather than JPA. This is done so that we can send over plain SQL commands, such as "SELECT * FROM ...", and to access the ResultSet's metadata, finding out the names of the columns in the result. The point of this exercise is to be able to print the table header (column names) into the output CSV file.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Executes a query, or several statements the last of which is a query.static void
static void
doQuery2
(Connection conn, String[] queries, File f) This one just sends commands to an existing connection, without closing itstatic void
-
Constructor Details
-
ExportTable
public ExportTable()
-
-
Method Details
-
main
- Throws:
Exception
-
doQuery
- Throws:
IOException
SQLException
-
doQuery
Executes a query, or several statements the last of which is a query. Prints out the result of the last query into a CSV file.- Throws:
IOException
SQLException
-
doQuery2
public static void doQuery2(Connection conn, String[] queries, File f) throws IOException, SQLException This one just sends commands to an existing connection, without closing it- Throws:
IOException
SQLException
-