Exporting data from mysql to csv file

Exporting data from mysql to csv file

Hi friends.... I want to export the data from mysql to csv file... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data in csv file..if i export am getting the csv file with all data in one row.. but i want the csv file to be in the order like text1,text2,text3 should be in the 1st row of csv file... text4,text5,text6 should be in the 2nd row and so on.... i want csv file with 10 rows.. pls help me soon..its very urgent..

View Answers

August 31, 2012 at 12:17 PM

Here is a java example that retrieves the data from the database and save it into csv file.

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

public class DatabaseToCSV { 
public static void main(String[]args){ 
  String filename = "c:\\myjdbcfile.csv";
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "test";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "root";
  Statement stmt;
  try
  {

  FileWriter fw = new FileWriter(filename);

  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection
   (url+dbName,userName,password);
  String query  = "select * from data";
  stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery(query);
  while(rs.next())
  {
  fw.append(rs.getString(1));
  fw.append(',');
  fw.append(rs.getString(2));
  fw.append(',');
  fw.append(rs.getString(3));
  fw.append(',');
  fw.append(rs.getString(4));
  fw.append(',');
  fw.append(rs.getString(5));
  fw.append(',');
  fw.append(rs.getString(6));
  fw.append(',');
  fw.append(rs.getString(7));
  fw.append(',');
  fw.append(rs.getString(8));
  fw.append(',');
  fw.append(rs.getString(9));
  fw.append(',');
  fw.append(rs.getString(10));
  fw.append('\n');
  }
  fw.flush();
  fw.close();
  conn.close();
  System.out.println("CSV File is created successfully.");
  } catch (Exception e) {
  e.printStackTrace();
  }

  }
}

August 31, 2012 at 12:30 PM

Thank you friend.. but can you give the code how to do it in jsp...









Related Tutorials/Questions & Answers:
Exporting data from mysql to csv file
Exporting data from mysql to csv file  Hi friends.... I want to export the data from mysql to csv file... i am having 30 columns in my database.. Eg... example that retrieves the data from the database and save it into csv file
Exporting data from mysql into csv using jsp
Exporting data from mysql into csv using jsp  Hi friends.... I want to export the data from mysql to csv file using... i am having 30 columns in my... in csv file..if i export, am getting the csv file with all data in one row
Advertisements
create dropdown cell in csv or excell from mysql data in php
create dropdown cell in csv or excell from mysql data in php  Hello sir i want to create drodown cell in csv from mysql data is this is possible or not? if this is posible please share answer or reference link Thanks
reading a csv file from a particular row
reading a csv file from a particular row  how to read a csv file from a particular row and storing data to sql server by using jsp servlet
Retrieve Data from CSV file in JSP
Retrieve Data from CSV file in JSP       CSV file : A CSV file is commonly known as a Comma... folder Create a Page ("ReadCsvFile.jsp") to retrieve the data from CSV
Export Database table to CSV File
Export Database table to CSV File In this tutorial, you will learn how to retrieve data from database and save it to CSV File. The Comma-separated values... similar to text files. Exporting or writing data to csv file is exactly same
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
PHP code for csv file upload into mysql
PHP code for csv file upload into mysql  I want to upload a file from my pc to mysql server using upload option. while i m selecting the csv file it ll be upload the mysql database. can u send me the coding? i have tried
Export data into CSV File using Servlet
Export data into CSV File using Servlet  ... to Export data into  CSV file using Servlet. We have created  file "JdbcCsvFile.java" to export data from this .java file.. Brief
php csv file uploding into mysql database table.
php csv file uploding into mysql database table.  hai friends, i... fields. i have one mysql database table with two files fields, when ever i am uploding csv file, i want to fetch the datas in corresponding fields in table. can
Wrong parameter values while exporting data from jsp to excel
Wrong parameter values while exporting data from jsp to excel   This is a jsp report. When i export the report data to an excel, the parameter...(); out.println("Data is saved in excel file."); }catch ( Exception ex ){ } %>
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... an example to insert data from file. To understand this example, we create
Retrieve The Data From MySql Datbase
Retrieve The Data From MySql Datbase   How to Retrieve The Data From MYSQL database TO Use Select the Emp_id Option.And Also Search Option
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.  i have MYSQL DB,DB NAME:TRLIST, TABLE NAME:TR_LIST... from table TR_LIST on typing TR values in an input-text-box and by clicking<
How to delete data from MySQL?
How to delete data from MySQL?  Hi, How I can conditionally delete the data from MySQL Table? Thanks   Hi, You can use the where clause to conditionally delete the data from MySQL database table. Here is some query
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... an example to insert data from file. To understand this example, we create
csv file download
csv file download  Hello Every one, when user clicks download button I want to retrieve data from mysql database table in csv format using java.if... the following link: JSP Retrieve data from MySQL Database
Export Data into CSV file uing JDBC in JSP
Export Data into CSV file uing JDBC in JSP       CSV file : A CSV file is commonly known...;) to export data into  CSV file "myjdbcfile.csv".  ADS
store data from a variable in mysql?
store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable... of the calculation from an int variable into mysql in a new table of database. how
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql...;/html> retcombosearch.php form is <?php mysql_connect ("localhost
convert excel file data into different locales while converting exclile file to csv file
convert excel file data into different locales while converting exclile file to csv file   can any one provide the code for how to convert excel file data into different locales while converting exclile file to csv file
Download CSV File from Database in JSP
Download CSV File from Database in JSP  ... and download the CSV file  from database. All CSV file will show... to download CSV  file from database in JSP.  In this example, we have
Data extraction from an image file.
Data extraction from an image file.  I have made an image... data from the the image which also include deleted data.Can i used java to extract these data from the image file? Which are the libraries to be used
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data save to database from JButton.Please give me a tutorial and source code
Expport data into CSV File using JDBC in Servlet
into CSV file using JDBC in Servlet. We have created  file "JdbcCsvFile.java" to export data from database in to CSV file. Brief... into CSV File using JDBC in Servlet   
Mysql CSV
: The keyword is used to import the data from text file to database in Mysql. Query for loading table data from csv file:ADS_TO_REPLACE_2 mysql>... file into database. Mysql CSV is used to load the text file and add to the table
Purge Data from Mysql tables
Purge Data from Mysql tables  Hi, i have to write a mysql procedure to purge data from tables. but written procedure clear entire tables data. Please give me the solution for purging data. CREATE DEFINER=`root`@`localhost
exporting data to excel sheet - JDBC
exporting data to excel sheet  Sir i have already send request about... = con.createStatement(); rs= st.executeQuery("Select * from data"); while(rs.next...; Form(){ String data[][] = {{"",""}}; String col[] = {"Name
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... from the dropdown, related data will get displayed on the textboxes. Here we have
How to save form data to a csv file using jquery or ajax
How to save form data to a csv file using jquery or ajax  Please let...=data.responseText; Now the problem is ,i should write form data to a csv file using ajax... this. i am able to read the csv file using this code if (window.XMLHttpRequest
php import data from excel to mysql
php import data from excel to mysql  php import data from excel to mysql
SQL Bulk Insert csv
; SQL Bulk Insert is used to import the records from csv  file... The Tutorial covers an example from 'SQL Bulk Insert CSV'.To understand and ... respectively.Again, we create a file abc  with extension csv contain
downloading a file directly from mysql using java
downloading a file directly from mysql using java  Hi, I am trying to come up with a code to download a file that is on a mysql database (in form of a blob) without using url. Can anyone tell me how it can be done because I am
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
how to save html form data into .csv file using only jsp.
how to save html form data into .csv file using only jsp.  Dear all, I am developing a website only using jsp and html. i need to save the form data into a .csv file using jsp. can anyone give me any sample solution or tutorial
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
read text file and store the data in mysql - JDBC
read text file and store the data in mysql  when we store the data in mysql table from text file its store the data from new line to new column. how to store the data in different column from a single line of text file
MYSQL retrieve record from Data table
MYSQL retrieve record from Data table  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from the field
pass data from java frame to file
pass data from java frame to file  i want to write the data to file, and data must be copy from java frame java frame contains 7-8 labels n below that 1 table. i want store all this data to 1 file. plz help me
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir , I am working on a project , in which I have to apply operation on input data which is stored in mysql. so to apply some arithmetic operation on it we have
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...(); in the below example. the error is "cannot convert from java.sql.Statement..."); con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost
extract data from excel sheet to mysql
extract data from excel sheet to mysql  sir, i want to extract data from excel sheet and save the data in mysql5.0 database in the form of table
Mysql Loader Control File
;    Mysql Loader Control File is the mean to import a data... The Tutorial illustrate an example from 'Mysql Loader Control File'.To grasp...; ); Query OK, 0 rows affected (0.03 sec) Query to load data from control file created
Mysql Loader Control File
Mysql Loader Control File is the mean to import a data... The Tutorial illustrate an example from 'Mysql Loader Control File'.To grasp..., 0 rows affected (0.03 sec) Query to load data from control file created above
access data from mysql through struts
access data from mysql through struts  I am Pradeep Kundu. I am making a program in struts in which i want to access data from MySQL through struts. I am using Strut 1.3.8 , Netbean 6.7.1 and MySQL 5.5. In this program ,I want
Fetching the exact data from file using java
Fetching the exact data from file using java  **hi ... i am having one .lst file.. that file consists of instructions and opcodes.. now i want to fetch only the opcode from that file.. could u pls anyone guide me this using java
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file

Ads