The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Importing and Exporting  [4 examples]

e295. Exporting a MySQL Table to a Flat File

The default format of a file exported from MySQL is as follows: the fields are separated by tabs, the lines terminated by '\n', and backslashes(\), newlines (\n), and tabs (\t) escaped by a backslash. NULL is exported as \N.

This example exports the data in a table called mysql_table2 to a file named outfile.txt.

    try {
        // Create the statement
        Statement stmt = connection.createStatement();
    
        // Export the data
        String filename = "c:\\\\temp\\\\outfile.txt";
        String tablename = "mysql_2_table";
        stmt.executeUpdate("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
    } catch (SQLException e) {
    }

 Related Examples
e292. Loading a Flat File to a MySQL Table
e293. Exporting an Oracle Table to a Flat File
e294. Loading a Flat File to an Oracle Table

See also: Batching    Connections    Database Meta Data    Deleting Data    Drivers    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Scrollable Result Sets    Tables    Updatable Result Sets   


© 2002 Addison-Wesley.