If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > LOAD DATA INFILE problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-06, 08:33
anandsatchin anandsatchin is offline
Registered User
 
Join Date: Oct 2006
Posts: 4
LOAD DATA INFILE problem

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

query
---------
LOAD DATA INFILE 'C:\\spares_import.txt'
INTO TABLE
fujitsu_spare_import (date_temp,time,scan_type,fujitsu_order_number,tec hnician_or_shippiment)

But when I do it java I am getting error

Error
-----------
java.sql.sqlException: General error message from server: "File 'C:spares_import.txt' not found <ErrCode: 2>"


1. The file and table exists
2. When I use Load query, its working fine

I dont know why its say like that and another thing,
why does it say C:spares_import.txt, instead of C:\spares_import.txt ?

Can anyone help me out in this

Thanks,
Anand



Code
----------

public Vector updateImportSparePartsBean()
throws ComponentFailureException, IllegalSupplyChainPCIStateException
{

Connection conn = null;
Statement st;
PreparedStatement stmt;
ResultSet rs;
Vector return_vec = new Vector();
FujitsuSparePartsBean fujitsuSparePartsBean = null;

int result = 0;

try{
conn = getConnection();
}
catch (Exception e){
}

String filename = "C:\\spares_import.txt";

try
{
st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,ResultSet.CONCUR_UPDATABLE);
String query = "LOAD DATA INFILE '"+filename+"' INTO TABLE fujitsu_spare_import (date_temp,time,scan_type,fujitsu_order_number,tec hnician_or_shippiment);";
System.out.println("string load file " + query);
st.executeUpdate(query);

}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error in loading file into fujitsu_spare_import \n");
st = null;
}

...

try
{
conn.close();
}catch (SQLException sqle)
{
//reportError("getSAGECustomerBean","SQLException raised whilst closing connection");
throw new ComponentFailureException("SQLException raised whilst closing connection" + sqle);
}

return return_vec;

}// end of method updateImportSparePartsBean


Details
----------
j2sdk1.4.2_04
MySQL 4.0.20
Reply With Quote
  #2 (permalink)  
Old 10-17-06, 09:26
anandsatchin anandsatchin is offline
Registered User
 
Join Date: Oct 2006
Posts: 4
Found solution - LOAD DATA INFILE problem

Hi guys ,

I have sorted out the problem! yahooooooooooo

code

try
{
Statement st = conn.createStatement();
// Load the data
String filename = "c:\\\\spares_import.csv";
String tablename = "fujitsu_spare_import";

// If the file is comma-separated, use this statement
st.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename + " FIELDS TERMINATED BY ','");
}
catch(Exception e)
{
e.printStackTrace();
st = null;
}


Thanks for all your help

Cheers,
Anand
Reply With Quote
  #3 (permalink)  
Old 11-28-11, 19:10
jesuscabarcas jesuscabarcas is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
load data infile java

Reply With Quote
  #4 (permalink)  
Old 01-01-12, 19:00
jesuscabarcas jesuscabarcas is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
Load data local Infile Java

Here you can see the solution
http://cabarcasprogramacion.*************
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On