2

I have used an application to import some data from a text file to mysql. I have used the following code.

try
{
   stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                               ResultSet.CONCUR_UPDATABLE);
   stmt1= (Statement) conn.createStatement();
   int deleteRows = stmt1.executeUpdate("delete  from powerdata where dateformat < dateformat_sub(now(), interval 8 month)");
   query = "LOAD DATA LOCAL INFILE \"E:\\powerdata.txt\" INTO TABLE powerdata  set dateformat=str_to_date(date, '%m/%d/%Y' '%H:%i:%s');";
   int Update= stmt.executeUpdate(query);
}

But the query to load the data from text to mysql is null. Can anybody tell me where I have made a mistake?

2
  • This code fragment appears to be missing useful context, such as the types of stmt, stmt1, query, etc; I'll wager they're something like Statement, Statement and String, but it's not obvious. Can you also rephrase the actual problem, with reference to your code if necessary? Commented Feb 24, 2009 at 8:47
  • i have given only try block and not the entire code. Commented Feb 24, 2009 at 8:49

2 Answers 2

1

Could it be that the problem is the \"E:\\powerdata.txt\" bit? You're escaping the quotes, but you're not escaping the backslashes. That means your query actually looks like this: LOAD DATA LOCAL INFILE "E:\powerdata.txt" INTO TABLE powerdata set dateformat=str_to_date(date, '%m/%d/%Y' '%H:%i:%s');

To fix the filename, use \"E:\\\\powerdata.txt\".

Sign up to request clarification or add additional context in comments.

Comments

0

You probably haven't given the user you are using FILE privileges. If you look over the documentation they talk about the privileges a remote user would need to load data using LOAD DATA LOCAL INFILE. There is a good reason this is turned off so be careful if you enable it.

1 Comment

i have executed the cmd sucessfully in mysql. The problem is that i am using the java application to do this and there i am having the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.