tags:

views:

58

answers:

4

I am want to export database table to a file.
I am using the following code, but it gives the following error.

String filename="D:/backup.txt";

I already create

st.executeQuery("select * from tamil into outfile'"+filename+"' fields terminated by ','");

But the error is:

java.sql.SQLException: Can't create/write to file 'D:\backup.txt' (Errcode: 13)

help me to clear the error
Thanks

A: 

but then you need to think how to put all this data into database.

you should consider mysqldump (or similar for other databases) http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

ever tried myphpadmin? you can easily manipulate your database with it.

fazo
A: 

Doesn't that error simply mean that you weren't allowed to write that file? Check if you can create a file with that name, in that location, for example using Notepad or by copying a file.

Thomas Padron-McCarthy
A: 

You need to remember that it will save it to the file on the computer that is running the database and NOT the computer running the java program. So for example, if the database computer is a Linux machine then

String filename="D:/backup.txt";

is definitely not going to work. So if you keep this in mind you can test why you cant write to D:/backup.txt.

Paul
I believe this is not strictly true. Otherwise, remote connections and such things as phpmyadmin would not exist.
Alfabravo
http://dev.mysql.com/doc/refman/4.1/en/select.htmlstates... The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed.
Paul
A: 

The thing is, this error points to the fact your program is not able to access resources (files). Strange as it seems -you're in a windows environment-, you might check if the user which is executing your java app is allowed to create files in D:\

Also, as fazo stated, you'd consider using mysqldump, smart stuff which handles the whole process of setting data and schemas as well, into a file.

Alfabravo