关于PreparedStatement插入数据报错的问题
我在数据库中执行 sql:INSERT INTO NEWS ( TITLE , MAINBODY , AUTHOR , PUBLISHDATE ) VALUES ( 'wwrw','erwerwerw','wer','2014-02-25' ); 时是没问题的,问题是我在后台时报
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'MAINBODY' in 'field list'错误,我的后台代码是这样写的:
String sql = " INSERT INTO NEWS( TITLE , MAINBODY , AUTHOR , PUBLISHDATE ) VALUE( ? , ? ,? , ? ); ";
Connection connection = null;
PreparedStatement preparedStatement = null;
connection = JdbcUtils.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, newBean.getTitle());
preparedStatement.setString(2, newBean.getMainBody());
preparedStatement.setString(3, newBean.getAuthor());
preparedStatement.setDate(4, new Date(new java.util.Date()
.getTime()));
preparedStatement.executeUpdate();
------解决方案--------------------VALUE改为VALUES,SQL语法错误。
------解决方案--------------------values
------解决方案--------------------缺个 S 呢。
这种地方最好拷贝复制比较靠谱。
------解决方案--------------------http://my.oschina.net/dddttttt/blog/85452
kan yixia zhege