473,520 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

61 New Member
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 17407
r035198x
13,262 MVP
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 New Member
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
12378
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 something like :id,text1html, text1raw,... . Problems : 1. Texts can contain html tags, including entities (" etc), so using only the ';' as...
11
4170
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 direct access to the db server. I'd like to give her the facility to export the information in her local Access application to the shared...
1
4022
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) Will running mysqldump from command line on a live in-use DB (with one table containing 350,000 rows) pose any risks and have any large effect of...
5
3291
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
3152
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 database using unicode compression field (for ancient language). I would like to export this table into MySQL o Postgres, but it's
3
2066
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 that I use. I would like to take a database that's on my website and change it over to use the MySql database. It's currently using a flat file with...
7
33375
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 need to know else (e.g. Navicat)? Thanks Phil
1
9757
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 having I'd be most appreciative. The database is already constructed, I'm just wanting to export the data to an excel file. In short, I'm hoping...
7
3565
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 to export the 1000 records to a new table on the server. If I use my code below, it takes 100 secods (10 records per second). Can someone help...
0
7206
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7444
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7564
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5749
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5127
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4790
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3284
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1652
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.