Tag: sql insert

以下sql代码无法插入数据的原因是什么?

我的数据库有两列。 一列是自动增量id(Primary Key) ,另一列是’Sentence’列。 手动输入内容,我可以插入该值。 但是当我尝试插入变量值时会出现错误消息。 我尝试了不同的方法。 (‘?’) /( ? )/(?)不适用于我。 int s1=9; String s2=”Kasuni”; String sql = “INSERT INTO sentences (Sentence) VALUES ( ? )”; PreparedStatement pstmtJ = conn.prepareStatement(sql); //pstmtJ.setInt(1, s1); pstmtJ.setString(1,s2); pstmtJ.executeUpdate(sql); 第一个值我没有插入因为那是自动增量值。 我只是评论,并在我上面的代码中显示。 错误信息: Exception in thread “main” com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds […]

PostgreSQL中的Query错误没有返回任何结果

我试图将数据插入表中。 执行查询后,我得到一个exception说明 org.postgresql.util.PSQLException: No results were returned by the query. org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:284) 数据插入成功,但我不知道为什么我得到这个例外?