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

Home Posts Topics Members FAQ

LOAD DATA INFILE problem....

61 New Member
Hi guys,

I have got a question regarding LOAD DATA INFILE. Can some one save my day.

1. I want to import a txt file into mysql database.
when I use the following query in the mysql> prompt its fine.
which is

when I do it java I am getting error

Error
-----------
java.sql.sqlExc eption: General error message from server:
"File 'D:/Sen.txt' not found <ErrCode: 2>"


But The file already exists

Code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.            con = DriverManager.getConnection(url, "root", "");
  3.             stmt = con.createStatement();
  4.             stmt.executeUpdate(createString);
  5.             String filename = "D:/Sen.txt";
  6.             String tablename = "IMPORT";
  7. stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename + " FIELDS TERMINATED BY ','");
  8.             stmt.close();
  9.             con.close();
  10. }
My text file(Sen.txt) is like this...

abc,1
bcd,2
adf,3

I dont know why its say like that
Can anyone help me out in this...

thanks...
senthil.
Feb 13 '07 #1
10 4226
123456prakash
35 New Member
Hi guys,

I have got a question regarding LOAD DATA INFILE. Can some one save my day.

1. I want to import a txt file into mysql database.
when I use the following query in the mysql> prompt its fine.
which is

when I do it java I am getting error

Error
-----------
java.sql.sqlExc eption: General error message from server:
"File 'D:/Sen.txt' not found <ErrCode: 2>"


But The file already exists

Code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.            con = DriverManager.getConnection(url, "root", "");
  3.             stmt = con.createStatement();
  4.             stmt.executeUpdate(createString);
  5.             String filename = "D:/Sen.txt";
  6.             String tablename = "IMPORT";
  7. stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename + " FIELDS TERMINATED BY ','");
  8.             stmt.close();
  9.             con.close();
  10. }
My text file(Sen.txt) is like this...

abc,1
bcd,2
adf,3

I dont know why its say like that
Can anyone help me out in this...

thanks...
senthil.

hi dude try this code
try {
Connection con = // getConnection here
// Create the statement
Statement stmt = con.createState ment();
String tablename = "IMPORT";
String filename = "D:\\\\Sen.txt" ;
String query = "LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename;
stmt.executeUpd ate(query);
} catch (Exception e) {
}
Feb 13 '07 #2
r035198x
13,262 MVP
Hi guys,

I have got a question regarding LOAD DATA INFILE. Can some one save my day.

1. I want to import a txt file into mysql database.
when I use the following query in the mysql> prompt its fine.
which is

when I do it java I am getting error

Error
-----------
java.sql.sqlExc eption: General error message from server:
"File 'D:/Sen.txt' not found <ErrCode: 2>"


But The file already exists

Code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2. con = DriverManager.getConnection(url, "root", "");
  3. stmt = con.createStatement();
  4. stmt.executeUpdate(createString);
  5. String filename = "D:/Sen.txt";
  6. String tablename = "IMPORT";
  7. stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename + " FIELDS TERMINATED BY ','");
  8. stmt.close();
  9. con.close();
  10. }
My text file(Sen.txt) is like this...

abc,1
bcd,2
adf,3

I dont know why its say like that
Can anyone help me out in this...

thanks...
senthil.
Must be some directory thing. I've never used it in Java myself. A quick check here shows that you have it right for running from mysql prompt. Java looks for the file starting in the current directory where your code is but mysql looks for the file from the database directory... Still trying to fihure out what would work there if you get it please post and tell us as well.
Feb 13 '07 #3
asenthil
61 New Member
Must be some directory thing. I've never used it in Java myself. A quick check here shows that you have it right for running from mysql prompt. Java looks for the file starting in the current directory where your code is but mysql looks for the file from the database directory... Still trying to fihure out what would work there if you get it please post and tell us as well.
Hey another one things...

But when i tried the filename = "C:/test.txt"

itz import the data from the database and load it to the text file perfectly..

but whatz special in this is.... there is no test.txt file in the C:/

Actually test.txt file is a created file by using Query

SELECT * INTO OUTFILE in the java program for export data to a file(C:/test.txt)..

When i run the above program...

there is no test.txt file in the C:/....

But when i tried to run the program again... its throwing exception

that C:/test.txt file is already exist... But there is no test.txt file..

i dont know what is happening here...

What to do for it...

plzz explain me....
Feb 13 '07 #4
r035198x
13,262 MVP
Hey another one things...

But when i tried the filename = "C:/test.txt"

itz import the data from the database and load it to the text file perfectly..

but whatz special in this is.... there is no test.txt file in the C:/

Actually test.txt file is a created file by using Query

SELECT * INTO OUTFILE in the java program for export data to a file(C:/test.txt)..

When i run the above program...

there is no test.txt file in the C:/....

But when i tried to run the program again... its throwing exception

that C:/test.txt file is already exist... But there is no test.txt file..

i dont know what is happening here...

What to do for it...

plzz explain me....
When you run it first time it creates the file right?
When you run it second time, do you delete that file first?
Feb 13 '07 #5
asenthil
61 New Member
When you run it first time it creates the file right?
When you run it second time, do you delete that file first?
Ya it is creating a file..... But it is not storing in c:/

i dont know where it is storing......

the file is storing in some other location...

the file is in invisible mode....
Feb 13 '07 #6
r035198x
13,262 MVP
Ya it is creating a file..... But it is not storing in c:/



i dont know where it is storing......



the file is storing in some other location...



the file is in invisible mode....


Let us eliminate all the other possibilities first.



Expand|Select|Wrap|Line Numbers
  1.  } catch (Exception e) {
  2. }
is not handling any exception. Change it to



Expand|Select|Wrap|Line Numbers
  1.  } catch (Exception e) { 
  2.  
  3. e.printStackTace();
  4.  
  5.  
  6. }
  7.  
  8.  




and run it to make sure the program is not throwing any exceptions
Feb 13 '07 #7
asenthil
61 New Member
Now also the same result....

i will explain u clearly..

When i want a export data from a database into a text file..

i used the query, SELECT * INTO OUTFILE 'C:/test.txt' FROM TABLE....

there is no test.txt file in C:/..i cant see it...

But when i run the program again, it throwing an exception that
C:/test.txt already exists....

thats what, i came to the conclusion that, the above query creating a file

and exporting the data into that file... but i think that created file is in

invisible mode...

Now i'm trying to importing data from database from a file...

in this i had used the following query...

stmt.executeUpd ate("LOAD DATA INFILE \"" + 'C:/test.txt' + "\" INTO TABLE " + tablename + " FIELDS TERMINATED BY ','");

its working perfectly running.... and importing the data from the test.txt file into

the database...

But whats special in this is.... there is no test.txt file in C:/


Can u understand what i'm saying?

Plzz tell me a solution for this....

thanks for replying...
senthil.
Feb 13 '07 #8
r035198x
13,262 MVP
Now also the same result....



i will explain u clearly..



When i want a export data from a database into a text file..



i used the query, SELECT * INTO OUTFILE \'C:/test.txt\' FROM TABLE....



there is no test.txt file in C:/..i cant see it...



But when i run the program again, it throwing an exception that

C:/test.txt already exists....



thats what, i came to the conclusion that, the above query creating a file



and exporting the data into that file... but i think that created file is in



invisible mode...



Now i\'m trying to importing data from database from a file...



in this i had used the following query...



stmt.executeUpd ate(\"LOAD DATA INFILE \\\"\" + \'C:/test.txt\' + \"\\\" INTO TABLE \" + tablename + \" FIELDS TERMINATED BY \',\'\");



its working perfectly running.... and importing the data from the test.txt file into



the database...



But whats special in this is.... there is no test.txt file in C:/





Can u understand what i\'m saying?



Plzz tell me a solution for this....



thanks for replying...

senthil.


Maybe some blocking as explained here..Wait a minute. I think this is taking the shape of a mysql problem so let me copy your post there as well so you can be able to view replies posted from there and here as well.
Feb 13 '07 #9
asenthil
61 New Member
Maybe some blocking as explained here..Wait a minute. I think this is taking the shape of a mysql problem so let me copy your post there as well so you can be able to view replies posted from there and here as well.
yeaaaaahhhhhhhh hhhhhh........

Hai r035198x....

i found the solution for that....

just we have add a LOCAL keyword in the query like this

stmt.executeUpd ate("LOAD DATA LOCAL INFILE \"" + filename + "\" INTO TABLE " + tablename + " FIELDS TERMINATED BY ','");

Now itz perfectly working...

Thanks for replying...
senthil
Feb 13 '07 #10

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

Similar topics

14
9738
by: Bruce A. Julseth | last post by:
When I execute this SQL statement in my PHP code, I get an error "File '.\Address.txt' not found (Errcode: 2)" $File = addslashes(".\Address.txt"); $SQL = "Load Data InFile \"" . $File . "\" into table addresses"; $result = mysql_query($SQL) or die(mysql_error()); The file is located in the same directory as my .PHP file. How do I generate a relative address for this file so that it can be found?
0
2360
by: Montagna, Dan | last post by:
------_=_NextPart_001_01C35B55.62B4A6E0 Content-Type: text/plain; charset="iso-8859-1" Hello, I'm a very new mysql/php user and am trying to use the load data infile command without luck. I'd like to replace a table using a text file but can't get it to work. I set up a test table with no records using a telnet console. I'm trying to write a php page that takes the file on the server and adds the info into the table. Here's my code:
0
6677
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to be able to place the PHP file on the server, and I guess you probably can't do that either. Talk about catch 22... The only other way I can think of is to install MySQL on a machine you control, then import the data there using the method I...
2
7046
by: Alex Hunsley | last post by:
I'm using a mysql monitor under cygwin (on win xp) to do a 'load data infile' to put some data into a mysql database (I'm using the xampp bundle).. My problem is that I have a four line CSV file beign inserted, but only two records actually get inserted: mysql> use master; delete from data; LOAD DATA INFILE 'D:/customJobs/database setup/dbaseFourLines.csv' REPLACE INTO TABLE data FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'...
6
2009
by: stefaan.lhermitte | last post by:
Dear mysql-ians, I am using mysql 5.0 and I want to load a huge txt-file in my database. My text file (file.txt) looks like: col1 col2 col3 ... col200 col1 col2 col3 ... col200 .... col1 col2 col3 ... col200
5
1888
by: Justin | last post by:
Hi, im facing a problem here. First of all here is my program requirement. I got a .csv file with thousands of records inside, i need to import them into my mysql database. So i tried using load data infile on my pc using localhost everything goes fine, but when i change the connection to my server, it seems tat the connection cant be done... so wat went wrong?
8
3563
seshu
by: seshu | last post by:
Hi Everybody this is seshu here i have doubt I have a piece of code to insert data into table which is there in a txt file and this is the code LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table; now is it possible load data from a excel file if so how i tried this but this is not working some one help me out regards seshu
9
3486
by: asenthil | last post by:
Hi guys, I have got a question regarding LOAD DATA INFILE. Can some one save my day. 1. I want to import a txt file into mysql database. when I use the following query in the mysql> prompt its fine. which is when I do it java I am getting error
0
2158
by: lanesbalik | last post by:
hi all, right now i'm trying to migrate from db2 running under linux to mysql v5.1. i manage to export out the db2 structure & data into a del (ascii) file. but when i try to load the data from the del file to mysql table, it generate an error. below is the load data infile syntax i use =
0
8675
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...
1
8334
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
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...
1
6108
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
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
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
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
1482
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.