java - load data from csv to mysql database using java
问题描述
I am working on a small application that will load data from a csv file into the database. Right now i encountered an error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Syntax error near 'csv FIELDS TERMINATED BY ',' (A,B,C)' à la ligne 1
Here's the code
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/testcsv","root","");
Statement st = connect.createStatement();
query = "LOAD DATA INFILE '"+filename+"' INTO csv FIELDS TERMINATED BY ',' (A,B,C)";
st.executeUpdate(query);
The variable filename is declared and assigned a value from a jTextField which is the file path. Also the variable connect is declared outside of the try-catch.
The user will browse for the file he wants to add to the database and from there i get the file path
Thank you
解决方案
推荐阅读
- flutter - 状态发生变化时如何导航到另一个屏幕
- wordpress - 创建新的自定义帖子时创建 Wordpress 用户
- wordpress - 是否可以将本地 WordPress 博客的 public 设置为 false
- python - 使用替换字典随机替换文件中的某些单词
- bash - 在 dokefile 运行指令中转义带有特殊字符和单引号的字符串
- matlab - 获取八度音阶中给定参数的列表
- java - 如何限制用户使用 Java Streams 从列表中仅选择两个枚举?
- java - 错误 69 87 何时使用生物特征验证 APDU 指令
- css - 将动态大小的 div 放置在另一个动态大小的 div 的底部
- odoo - Odoo 无法解析我的 xml 文件中的树视图