0
我在尝试使用java将值从csv插入到数据库时收到语法错误。这里是我的代码MySQLSyntaxErrorException:SQL插入语法错误
try{
BufferedReader br=new BufferedReader(new FileReader(filename1));
String line;
while((line=br.readLine())!=null){
String[]value=line.split(",");//Seperator
System.out.println(value[0]);
System.out.println(value[1]);
System.out.println(value[2]);
if (programused == "Example"){
String sql="insert into websitehistory (Date, URL, VisitCount) "
+ "values (?,?,?)";
pst=conn.prepareStatement(sql);
pst.setString(1, value[0]);
pst.setString(2, value[1]);
pst.setString(3, value[2]);
pst.executeUpdate(sql);
Update_exampleTable();
}
这里是将查询值插入数据库的mysql查询。值是包含在推杆csv文件,“文件名1”
这是我的表结构的数组:
Field Type Null Key Default Extra
Date text No NULL
URL text No NULL
VisitCount text No NULL
这是我想插入的CSV文件中的数据的类型:
31/01/2014 15:26:00, https://www.youtube.com/, 13
31/01/2014 15:25:00, https://www.youtube.com/, 17
30/01/2014 12:15:00, https://www.facebook.com/, 20
这则抛出一个MySQL的语法错误:
Check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?)' at line 1.
如果我更换?
与value[0] value[1]
等等,一些数据被插入,但检索给出了数据中的不同的SQL语法错误,但是当使用占位符时,没有数据被插入到表中。任何帮助都会很棒。