This is not how you should create and execute a SQL INSERT query with variables. This is not only subject to SQL injection attacks , but also quite .. cumbersome;) Perhaps the value contained one value and caused your query to be syntactically invalid.
SQL. PreparedStatement ( ) ? SQL. , Java ( Date InputStream!)) SQL , , SQL- (, , SQL-).
, SQL:
private static final String SQL_INSERT = "INSERT INTO CURRENT_WEATHER_US"
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
public void create(String cityCode, Weather weather) throws SQLException {
try (
Connection connection = database.getConnection();
PreparedStatement statement = connection.prepareStatement(SQL_INSERT);
) {
statement.setString(1, cityCode);
statement.setString(2, weather.getCity());
statement.setString(3, weather.getRegion());
statement.setString(20, weather.getForecastCode());
statement.executeUpdate();
}
}
JDBC , .
, .