Hey guys. Can anybody tell me what is wrong with this line of SQL? I keep getting a syntax error message.

Here is the line:

prepStat = connection.prepareStatement("INSERT INTO WeatherHistory (Date, Location, Overview, Temperature, WindDirection, WindSpeed, Pressure) VALUES ('"+date+"','"+location+"','"+temp+"','"+windDir+"','"+windSpd+"','"+pressure+"')");

All the field names and variables exist correctly, so I really can't see what is wrong here!

Thanks!

Try to print it and then run it to an sql client or an sql editor and see what is the problem:

..
String query = "INSERT INTO WeatherHistory (Date, Location, Overview, Temperature, WindDirection, WindSpeed, Pressure) VALUES ('"+date+"','"+location+"','"+temp+"','"+windDir+"','"+windSpd+"','"+pressure+"')";

System.put.println(query);

prepStat = connection.prepareStatement(query);

Take what is printed and run it. Also you can post it here with the values that you entered.

The above are for general debugging in case you have any future errors. After looking at the query, I would like to ask:

The Date column, what type is it? Is it type VARCHAR2 or type DATE. If it is type DATE then I don't think that this would work: ('"+date+"', Also, and I don't know if it is a problem or not, I believe that "date" is a reserved word for the sql and you cannot use it to name columns. If that is the problem, you can try to rename it to weather_history_date

It appears that you have a mismatch in the number of variables. There are 7 in the INPUT statement and 6 in the VALUES statement. Try removing Overview from the INPUT statement.

This question has already been answered. Start a new discussion instead.