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………..
statement=connection.prepareStatement("UPDATE login SET user_name ='"+userName+"' WHERE id ="+userID+""); int rows=statement.executeUpdate(); trace("rows-------------------"+ rows);
Here is full source………
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(); } } }
Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts
If you want any of my script need to be customized according to your business requirement,
Please feel free to contact me [at] muni2explore[at]gmail.com
Note: But it will be charged based on your customization requirement