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...
Ads
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
Export Database table to CSV File
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... third
party library.
Output:
Data is saved to
csv file
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... a Page ("ReadCsvFile.jsp") to retrieve the
data from CSV file
"
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
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
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
Insert Data From File
Insert
Data From File
Insert
Data From File is used to insert
data from file... to insert
data from file. To understand
this example, we create a table 'Stu_Table
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
Mysql CSV
to import the
data from text
file to
database in
Mysql.
Query for loading table
data from csv file:
mysql> load
data infile "C:/g.csv...
file into database.
Mysql CSV is used to load the text
file and add
to the table
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
Insert Data From File
Insert
Data From File
Insert
Data From File is used to insert
data from file... to insert
data from file. To understand
this example, we create a table 'Stu_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
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
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
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
Download CSV File from Database in JSP
Download
CSV File from Database in JSP
 ... file
from database. All
CSV file will show as
hyperlink.
2... to download
CSV
file from database in JSP. In this example, we have
SQL Bulk Insert csv
;
SQL Bulk Insert is used to import the records
from csv
file... an example
from 'SQL Bulk Insert
CSV'.To understand
and grasp this example... respectively.Again, we create a
file abc with extension
csv
contain the records
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
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