I have a problem using LOAD DATA INFILE commond .
I created a table using the command below;
temp.executeUpdate("CREATE TABLE Patient (patientID INT AUTO_INCREMENT, name VARCHAR(100),address VARCHAR(150), phone VARCHAR(15), birthdate DATE, PRIMARY KEY (patientID))");
and trying to read from a file using this command;
temp = connect.createStatement();
temp.executeUpdate("LOAD DATA LOCAL INFILE 'patient.txt' INTO TABLE Patient {name,address,phone,birthdate} FIELDS ENCLOSED BY '\"' ");
temp.executeUpdate(" UPDATE Patient SET name=NULL WHERE name= '-' ");
temp.executeUpdate( " UPDATE P开发者_Go百科atient SET address = NULL WHERE address = '-' ");
temp.executeUpdate(" UPDATE Patient SET phone = NULL WHERE phone = '-' ");
temp.executeUpdate(" UPDATE Patient SET birthdate = NULL WHERE birthdate = '-'");
and my sample text file is this;
"omer" "trabzon" "3253008" 1990-06-10
"ali" "ankara" "2234887" 1999-11-12
However it can't read the first fields and skip to the second ones.So, second fields are replaced to the first fields.
could you help to get the first fields into the right places?
thanks
add a "\N" before "omer" and before "ali" (at the beginning of each row) for the autoincrement column. I would enclose also the date with quotes
I have just found out that problem was the sequence of the load data file line. the right sequence is
temp.executeUpdate("LOAD DATA LOCAL INFILE 'patient.txt' INTO TABLE Patient FIELDS ENCLOSED BY '\"' {name,address,phone,birthdate}")
精彩评论