Find number of affected rows by MySQL UPDATE query in Java
In java executeUpdate() function of Preparedstatement returns integer which gives numbers of rows affected for particular MySQL updation……….
Here is the simple code how to access number of affected rows MySQL UPDATE query in Java………..
|
1 2 3 |
statement=connection.prepareStatement("UPDATE login SET user_name ='"+userName+"' WHERE id ="+userID+""); int rows=statement.executeUpdate(); trace("rows-------------------"+ rows); |
Here is full source………
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
package com.game; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.smartfoxserver.v2.db.IDBManager; import com.smartfoxserver.v2.entities.User; import com.smartfoxserver.v2.entities.data.ISFSObject; import com.smartfoxserver.v2.extensions.BaseClientRequestHandler; public class UpdateHandler extends BaseClientRequestHandler{ @Override public void handleClientRequest(User user, ISFSObject params) { // TODO Auto-generated method stub int userID=params.getInt("userID"); String userName=params.getUtfString("userName"); IDBManager dbManager=getParentExtension().getParentZone().getDBManager(); Connection connection=null; PreparedStatement statement=null; try { connection=dbManager.getConnection(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { statement=connection.prepareStatement("UPDATE login SET user_name ='"+userName+"' WHERE id ="+userID+""); int rows=statement.executeUpdate(); trace("rows-------------------"+ rows); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
Subscribe to get all tutorial updates, promotional offers and download links for all tutorials via E-Mail
Comments






Way cool! Some very valid points! I appreciate you writing
this article plus the rest of the site is extremely good.