sql - How to save variable acquired from method for later use in Java? -


i have 3 classes, main, pin, , employee. (more classes added in future)

the main class runs program prompts use enter password method in pin class. password sent using sql database verified methods in employee , pin classes. if password matches, returns id of employee.

the problem having saving id. retrieved id, want able use id rest of program. want save in employee class returned in method pin class. how able save id used employee class, or class?

hmm, if understand correctly may want composition of employee , pin?

employee e = ...  e.setpin(pin); 

or problem, don't know how assign specific pin employee, still assigned employee in next run of application?

update: after receiving more information: need create application context program. seems standalone application 1 user @ time, can static field in class.

if application multi-user application, context needs static per user.

if application web-application, application scope session, terminated during logout. (that not precise, session session scope, , application scope context of application. in case, pin session scoped.)

a sample standalone/single user application:

public class applicationcontext {      static applicationcontext ctx;     public static applicationcontext get() {         if( ctx == null ) {             ctx = new applicationcontext();         }         return ctx;     }      private pin pin;     public pin getpin() { return pin; }     public void setpin(pin pin) { this.pin = pin; }      // ... add more stuff here ...      public void logout() {         ctx = null;     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -