This solution only works if your classes contain a property that acts as an ID (i.e. annotated with @XmlID
).
One of the classes has to implement the interface CycleRecoverable
which provides the sole method Object onCycleDetected(Context ctx)
.
When overriding this method return an object that only contains the ID of that class e.g.:class A implements CycleRecoverable {
public Object onCycleDetected(Context ctx) { return new A(this.id); }
}
As for the fact that KeyListener does not work for JApplet as it does for Applet you should use the KeyEventDispatcher interface.
public class AppletMain extends JApplet implements java.awt.KeyEventDispatcher
Furthermore you have to set the KeyboardFocusManager to the Panel
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
Afterwards override the dispatchKeyEvent function of the interface:
@Override
public boolean dispatchKeyEvent(KeyEvent e);
This allows you to catch the KeyEvents as it is done with KeyListener.
To prevent a SQL-Injection, one should use prepared statements instead of normal statements. Why? Because a variable's SQL-metacharacters, passed as arguments to prepared statements, will automatically be escaped by the JDBC driver.
Example:
String selectStatement = "SELECT * FROM User WHERE userId = ? ";
PreparedStatement prepStmt = con.prepareStatement(selectStatement);
prepStmt.setString(1, userId);
ResultSet rs = prepStmt.executeQuery();
Incorrect usage of prepared statements can render their protective aspect inert.
Example:
String strUserName = request.getParameter("Txt_UserName");
PreparedStatement prepStmt = con.prepareStatement("SELECT * FROM user WHERE userId = '+strUserName+'");