Jump to content
  • 0

Retrieving Last_IP Field from accounts table


Question

Posted

Hello everyone, is there anyway to retreive last_Ip from account table in java?

i'm working on some code and in it i need to compare some IPs, but if using the getClient().getConnection().. method it doesnt always go smoothly, as it needs alot addational checks in my case..

 

Can someone tell me how can i get that last_ip field with java?

thanks

1 answer to this question

Recommended Posts

  • 0
Posted
import javolution.util.FastMap;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.l2jserver.L2DatabaseFactory;

public final class LastIPTable
{
public static FastMap<String, String> cachedLastIPs = new FastMap<String, String>();

static 
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement st = con.prepareStatement("SELECT login, lastIP FROM accounts");
		ResultSet rset = st.executeQuery();
		while(rset.next())
		{
			cachedLastIPs.put(rset.getString("login"), rset.getString("lastIP"));
		}
		rset.close();
		st.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	finally
	{
		L2DatabaseFactory.close(con);
	}
}

public static String getLastIP(final String account)
{
	return cachedLastIPs.get(account);
}

// Should be called on player's log out
public static void updateLastIP(final String account, final String lastIp)
{
	cachedLastIPs.put(account, lastIP);
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...