Thursday, June 13, 2013

java.sql.SQLException: No value specified for parameter 3


#Problem:
(1)
java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '1' for key 'PRIMARY'"
(2)

java.sql.SQLException: No value specified for parameter 3
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2368)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1799)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1667)




 pst = con.prepareStatement(sql);

  pst.setString(1"Rakesh");
  pst.setString(2"Kanwal");
  pst.setString(3"Delhi");
  pst.setString(4null);

ResultSet + prepared statement




13
down voteaccepted
If you have access to the prepared statement that results in this resultset, you can use
connection.prepareStatement(sql, 
  ResultSet.TYPE_SCROLL_INSENSITIVE, 
  ResultSet.CONCUR_READ_ONLY);
This prepares your statement in a way that you can rewind the cursor. This is also documented in the ResultSet Javadoc:
In general, however, forwarding and rewinding cursors may be quite inefficient for large result sets. Another option in SQL Server would be to calculate the total number of rows directly in your SQL statement:
SELECT my_table.*, count(*) over (partition by 1) total_rows
FROM my_table
WHERE ...

How to enable the column selection mode in Eclipse?


Toggle Block Selection Mode