I am receiving a syntax error when trying to insert values from a csv to a database using java. Here is my code

   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();

 }

Here is mysql query of inserting the separated values into the database. Value is an array that contains the in putted csv file, "filename1"

This is my table structure:

Field          Type     Null    Key     Default      Extra
Date           text     No              NULL
URL            text     No              NULL
VisitCount     text     No              NULL

And the type of data that is inside the csv file that I would like to insert:

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

This then throws a MySQL syntax error:

Check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?)' at line 1.

If I replace the ? with value[0] value[1] and so on, some of the data is inserted but retrieves gives a different SQL syntax error within the data but when using place holders none of the data is inserted into the table. Any help would be fantastic.

share|improve this question
up vote 0 down vote accepted

You should call:

pst.executeUpdate();

Instead of:

pst.executeUpdate(sql);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.