java中的PreparedStatement值错误

时间:2014-04-21 14:25:04

标签: java sql prepared-statement mssql-jdbc

以下代码在关键字' VALUES'附近提供"不正确的语法。"我找不到我的SQL语句的问题。

/ *                  * SQL Server中HistoryData表的表结构                  * 1)City_ID - int                  * 2)City_Name - nvarchar(50)                  * 3)时间 - 日期时间                  * 4)Received_Time - datetime                  * 5)湿度 - 漂浮                  * 6)Rain_info - 浮动                  * 7)Snow_info - 浮动                  * 8)温度 - 浮动                  * 9)Min_Temperature - 浮点数                  * 10)Max_Temperature - 浮动                  * 11)描述 - nvarchar(50)                 * /

            try 
            {
                String statementString = "INSERT INTO WeatherHistoryX("
                     +"City_ID,"
                     +"City_Name,"
                     +"Time,"
                     +"Received_Time,"
                     +"Humdity,"
                     +"Rain_Info,"
                     +"Snow_Info,"
                     +"Temperature,"
                     +"Min_Temperature,"
                     +"Max_Temperature,"
                     +"Description,"
                     +"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

                pStatement = connection.prepareStatement(statementString);

                //statement = null;
                //statement = connection.createStatement();

                java.sql.Date sqlDate = new java.sql.Date(weather.getDate());
                java.sql.Date currentSqlDate = new java.sql.Date(currentTimestamp.getTime());                   

                pStatement.setInt(1, weather.getCityCode());
                pStatement.setString(2, weather.getCity());
                pStatement.setDate(3, sqlDate);
                pStatement.setDate(4, currentSqlDate);
                pStatement.setFloat(5, weather.getHumidity());
                pStatement.setFloat(6, weather.getRainInfo());
                pStatement.setFloat(7, weather.getSnowInfo());
                pStatement.setFloat(8, weather.getTemperature());
                pStatement.setFloat(9, weather.getMinTemperature());
                pStatement.setFloat(10, weather.getMaxTemperature());
                pStatement.setString(11, weather.getDescription());

                pStatement.execute();

1 个答案:

答案 0 :(得分:3)

描述后你有一个额外的“,”。

只需删除该逗号并添加“)”和空格。