,

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…

1
How to find out Number of affected rows of MySQL update query in Java

In java executeUpdate() function of Preparedstatement returns integer which gives numbers of rows affected for particular MySQL updation……….

How to find out Number of affected rows of MySQL update query in Java
How to find out Number of affected rows of MySQL update query in Java

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();
		}

	}

}

 

 

 .

One response to “Find number of affected rows by MySQL UPDATE query in Java”

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

Leave a Reply