473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to export table data from a mysql database into text file using java?

Hai,

i'm a beginner to java...

just now i had tried to read and write files using java...

and then i had tried to connect a database using jdbc...

now i want to export the data's from a database into a text file

using java....

Can any one plzz give me an idea for doing this process...

thanks and regards..
senthil.
Feb 9 '07 #1
2 17372
r035198x
13,262 8TB
Hai,

i'm a beginner to java...

just now i had tried to read and write files using java...

and then i had tried to connect a database using jdbc...

now i want to export the data's from a database into a text file

using java....

Can any one plzz give me an idea for doing this process...

thanks and regards..
senthil.
Write files using BufferedWriter and FileWriter
Feb 9 '07 #2
maeon3
1
Output it to a file:

Expand|Select|Wrap|Line Numbers
  1.  SELECT agent_index, program_name, description 
  2. INTO OUTFILE "/tmp/my_table_widgets.out" 
  3. FROM my_table_widgets

Then to get it back:

Expand|Select|Wrap|Line Numbers
  1.  LOAD DATA LOCAL INFILE '/tmp/my_table_widgets.out'
  2. INTO TABLE my_table_widgets
  3. FIELDS TERMINATED BY '\t'
  4. LINES TERMINATED BY '\n'
  5. (agent_index, program_name, description);

Here is the java to do it:

Expand|Select|Wrap|Line Numbers
  1.  try {
  2.   Class.forName(Driver);
  3.   con = DriverManager.getConnection(connect_url);
  4.  if(!con.isClosed()){
  5.       stmt = con.createStatement(); 
  6.  
  7.     stmt.executeQuery("SELECT agent_index, program_name, description " +
  8. "INTO OUTFILE '/tmp/my_table_widgets.out' " +
  9. "FROM my_table_widgets ");
  10. }
  11. }
  12. catch(Exception e) {
  13.    System.err.println("Exception: " + e.getMessage());
  14.     } 
  15. finally {
  16.       try {
  17.         if(con != null)
  18.           con.close();
  19.       } catch(SQLException e) {}
  20.  }
  21. }
  22. }
Jul 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Damien | last post by:
Hi to all, I need to design an import/export system. Data comes from a filemaker pro DB in a big CSV file. Some alterations are made on the data as it is imported into my mysql table. Data is...
11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
1
by: Dave Crypto | last post by:
Hi there, SUMMARY: 1) When I use phpadmin to export a large database, the file created on my local PC never containes all the tables and information. It seems to max out at about 10mb. 2)...
5
by: Kajol | last post by:
Hi All, can u plz tell me how to import data from mysql to another database. & how to export data from anotherdata base to mysql Thanx for ur Advice Regards Kajol
4
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have created a populated a Access...
3
by: Cynthia | last post by:
Hi all, I know this can be done, but I just can't seem to find a way to do it (that I can use myself, or understand). I use Mac and I've got some databases on my hosting company's MySql server...
7
by: phillip.s.powell | last post by:
We're looking at a GUI interface for our MySQL DB and I am interested in MySQL Administrator, however, one of our requirements is to be able to import/export databases. Is this possible or do I...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
7
by: eselk | last post by:
I'm doing some speed tests. I created a brand-new table, with just one "Long Integer" field. I'm testing adding 1000 records. If I use the "Export" feature in Access, it takes only a few seconds...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.