如何解決這個錯誤,並使加載數據查詢打開我的文件?線程「main」中的異常java.sql.SQLException:無法打開文件
我得到java.sql.SQLException:嘗試從文件創建語句時無法打開文件。代碼:
public class LoadData {
public static void main(String[] args) throws Exception {
File file=new File("C://Users//suriyan.s//Documents//suriyan//employees.csv");
String filename = file.getAbsolutePath();
System.out.println(filename);
String tablename = "employee";
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/college", "root", "");
// Load the data
String qry = "LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE " + tablename + " FIELDS TERMINATED BY ','"
+ " LINES TERMINATED BY '\n';";
Statement stmt = connection.createStatement();
stmt.execute(qry);
}
}
你能打印出完整的查詢並顯示給我們嗎?我的猜測是某處有一個小錯字。它看起來像你在單引號中圍繞文件路徑。 –