Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7042633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:31+00:00 2026-05-28T02:11:31+00:00

I am able to export mysql to csv file but i am not getting

  • 0

I am able to export mysql to csv file but i am not getting table headers, I want headers to be displayed when my file gets saved to my system.

This is the java code which I am using:

import java.io.*;
import java.sql.*;

public class ExportData {

    public static void main(String args[]) {
        String Driver;
        Statement stmt;
        Driver = "com.mysql.jdbc.Driver";
        Connection con = null;

        try {
            Class.forName(Driver);
            con = DriverManager.getConnection(
                  "jdbc:mysql://localhost/emp", "root", "");
            if (!con.isClosed()) {
                System.out.println("Successfully connected to MySQL DataBase \n");
                stmt = con.createStatement();
                String filename = "C:/2.txt";
                String tablename = "employees";
                String sql;
                stmt.executeUpdate("SELECT * INTO OUTFILE \""
                        + filename + "\" FROM " + tablename);
            }
        } catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        } finally {
            try {
                if (con != null) {
                    con.close();
                }
            } catch (SQLException e) {
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:11:32+00:00Added an answer on May 28, 2026 at 2:11 am

    Here’s an example that was attached as a comment to the relevant MySQL manual page:

    select 'idPago','fecha','lead','idAlumno','idTipoPago','idGpo',
        'idTaller','idDocente','pagoImporte','NoFactura','facturaImporte',
        'mes','formaPago','observaciones' union all
    (select id_control_pagos, fecha, lead, id_alumno, id_concepto_pago, id_Gpo,id_Taller,
        id_docente, Pagoimporte, NoFactura, FacturaImporte, Mensualidad_No, FormaPago,
        Observaciones from control_pagos
        into outfile 'c:\\data.csv'
        FIELDS TERMINATED BY ','
        OPTIONALLY ENCLOSED BY '"'
        LINES TERMINATED BY '\n');
    

    In short, you have to add the column labels by hand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want users to be able to export data as an XML file. Of
I have an HTML table that I'd like to be able to export to
to export some data i want to be able to generate an html output.
Application able to record error in OnError, but we are not able to do
I'm able to connect to and read an excel file no problem. But when
I am trying to do 2 output data from mysql to a csv file.
I have tried a lot but I have not been able to find out
I'd like to be able to export my Core Data entity to a CSV
I have a gridvidew (GV2). I want the user to be able to export
do i need to install Microsoft Excel to be able to export xls file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.