473,651 Members | 2,994 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 17442
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
12385
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 separator does not work. 2. Some line are so long that is appears php breaks them down, so I lose
11
4188
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 PHP/MySql site. From one command button (or similar) in the Access application.
1
4031
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 current use?
5
3297
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
3162
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
2074
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 pipes (|) to delineate each field. The "converters" I've found online are all for Windows, and...
7
33398
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
9770
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 to export two Tables (or queries...not sure which to use - they both seem to have the same data) in...
7
3570
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 me speed up my code? --- code --- Dim con As New ADODB.Connection
0
8361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7299
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.