java - Update database in one frame and show updated values in another -
i have created banking system user can deposit (for now). program uses ms access database. i've loaded database; working enough. except, when user makes deposit, while database being updated @ click of "deposit" button, user has log out , log in see updated balance (this in frame called "account details).
is there way refresh database @ click of button refreshes throughout entire program? i've been looking @ arrays. can store database in array , call in account details window? if so, how can this?
loaddata window loading database
public static account accounts[] = new account[2]; public static customer people[] = new customer[2]; public static creditcard credit[] = new creditcard[2]; public static mortgage mortgage[] = new mortgage[2]; public static transaction trans[] = new transaction[100]; loaddata() { int = 0; try { //connect database connection conn = drivermanager.getconnection("jdbc:ucanaccess:///volumes/green grass/jsproject/prjtims_js/bank11.mdb"); statement st = conn.createstatement(); system.out.println("connected database successfully."); //retrieve data salesperson table string sqlaccount = "select * tblaccount"; resultset rsaccount = st.executequery(sqlaccount); //loop through results load data salesperson array while (rsaccount.next()) { //retrieve column name int cid = rsaccount.getint("custid"); int can = rsaccount.getint("checkingacctnum"); int san = rsaccount.getint("savingsacctnum"); int soan = rsaccount.getint("soaracctnum"); string ccan = rsaccount.getstring("creditcardacctnum"); int man = rsaccount.getint("mortgageacctnum"); int clan = rsaccount.getint("carloanacctnum"); double cab = rsaccount.getdouble("checkingacctbal"); double sab = rsaccount.getdouble("savingsacctbal"); double soab = rsaccount.getdouble("soaracctbal"); //load record salesperson array accounts[i] = new account(cid,can,san,soan,ccan,man,clan,cab,sab,soab); i++; } rsaccount.close(); system.out.println("loaded tblaccount table."); //retrieve data customer table string sqlcustomer = "select * tblcustomer"; resultset rscustomer = st.executequery(sqlcustomer); = 0; //loop through results load data customer array while (rscustomer.next()) { //retrieve column name int cid = rscustomer.getint("custid"); string ti = rscustomer.getstring("title"); string fn = rscustomer.getstring("fname"); string ln = rscustomer.getstring("lname"); string un = rscustomer.getstring("username"); string pw = rscustomer.getstring("password"); int sn = rscustomer.getint("ssn"); string uid = rscustomer.getstring("uniqueid"); string sk = rscustomer.getstring("sightkey"); int hn = rscustomer.getint("housenum"); string stn = rscustomer.getstring("streetname"); string ci = rscustomer.getstring("city"); string sta = rscustomer.getstring("state"); int zc = rscustomer.getint("zipcode"); string pn = rscustomer.getstring("phonenum"); string em = rscustomer.getstring("email"); //load record customer array people[i] = new customer(cid,ti,fn,ln,un,pw,sn,uid,sk,hn,stn,ci,sta,zc,pn,em); i++; } rscustomer.close(); system.out.println("loaded tblcustomer table."); //retrieve data car table string sqlcreditcard = "select * tblcreditcard"; resultset rscreditcard = st.executequery(sqlcreditcard); = 0; //loop through results load data customer array while (rscreditcard.next()) { //retrieve column name int cid = rscreditcard.getint("custid"); string ld = rscreditcard.getstring("loandate"); float air = rscreditcard.getfloat("annualinterestrate"); double la = rscreditcard.getdouble("loanamount"); double bal = rscreditcard.getdouble("balance"); int lt = rscreditcard.getint("loanterm"); double cmp = rscreditcard.getdouble("ccmonthlypayment"); //load record car array credit[i] = new creditcard(cid,ld,air,la,bal,lt,cmp); i++; } //close result sets , connection rscreditcard.close(); //retrieve data car table string sqlmortgage = "select * tblmortgage"; resultset rsmortgage = st.executequery(sqlmortgage); = 0; //loop through results load data customer array while (rsmortgage.next()) { //retrieve column name int cid = rsmortgage.getint("custid"); string mld = rsmortgage.getstring("mloandate"); float hv = rsmortgage.getfloat("homevalue"); double mla = rsmortgage.getdouble("mortloanamount"); double mair = rsmortgage.getdouble("mortannualinterestrate"); int mlt = rsmortgage.getint("mortloanterm"); double mmp = rsmortgage.getdouble("mortmonthlypayment"); double tp = rsmortgage.getdouble("totalpayments"); //load record car array mortgage[i] = new mortgage(cid,mld,hv,mla,mair,mlt,mmp,tp); i++; } //close result sets , connection rsmortgage.close(); system.out.println("loaded tblmortgage table."); //retrieve data car table string sqltransaction = "select * tbltransaction"; resultset rstransaction = st.executequery(sqltransaction); = 0; //loop through results load data customer array while (rstransaction.next()) { //retrieve column name int tc = rstransaction.getint("transcount"); int cid = rstransaction.getint("custid"); int tn = rstransaction.getint("transnum"); string tt = rstransaction.getstring("transtype"); string td = rstransaction.getstring("transdate"); //load record car array trans[i] = new transaction(tc,cid,tn,tt,td); i++; } //close result sets , connection rstransaction.close(); system.out.println("loaded tbltransactions table."); conn.close(); } catch (exception e) { system.out.println("can't get" +e); } }
account details window (i know has done in window reflect updated balance made in deposit window, not sure how)
public accountdetailswindow(int customerindex) throws ioexception{ //this shows balances , account numbers //i know need insert here reflect new balance changes, if jlabel lblcbal = new jlabel("$"+loaddata.accounts[customerindex].getcheckingacctbal()); lblcbal.setfont(new font("helvetica", font.plain, 11)); jlabel lblsbal = new jlabel("$"+loaddata.accounts[customerindex].getsavingsacctbal()); lblsbal.setfont(new font("helvetica", font.plain, 11)); jlabel lblsobal = new jlabel("$"+loaddata.accounts[customerindex].getsoaracctbal()); lblsobal.setfont(new font("helvetica", font.plain, 11)); jlabel lblccbal = new jlabel("$"+loaddata.credit[customerindex].getbalance()); lblccbal.setfont(new font("helvetica", font.plain, 11)); jlabel lblmbal = new jlabel("$"+loaddata.mortgage[customerindex].gettotalpayments()); lblmbal.setfont(new font("helvetica", font.plain, 11)); jlabel lblcacct = new jlabel("#"+loaddata.accounts[customerindex].getcheckingacctnum()); lblcacct.setforeground(new color(245, 135, 79)); lblcacct.setfont(new font("helvetica", font.plain, 11)); jlabel lblsacct = new jlabel("#"+loaddata.accounts[customerindex].getsavingsacctnum()); lblsacct.setforeground(new color(245, 135, 79)); lblsacct.setfont(new font("helvetica", font.plain, 11)); jlabel lblsoacct = new jlabel("#"+loaddata.accounts[customerindex].getsoaracctnum()); lblsoacct.setforeground(new color(245, 135, 79)); lblsoacct.setfont(new font("helvetica", font.plain, 11)); jlabel lblccacct = new jlabel("#"+loaddata.accounts[customerindex].getcreditcardacctnum()); lblccacct.setforeground(new color(245, 135, 79)); lblccacct.setfont(new font("helvetica", font.plain, 11)); jlabel lblmacct = new jlabel("#"+loaddata.accounts[customerindex].getmortgageacctnum()); lblmacct.setforeground(new color(245, 135, 79)); lblmacct.setfont(new font("helvetica", font.plain, 11));
deposit window contains methods updating balances deposits made.
public static int = 0; double dtsoar, dtchecking, dtsavings, newcb, newsb, newsob; double checkamount; int transnum = 4; string transtype = "deposit"; // current date time java.util.date date = new java.util.date(); timestamp ts = new timestamp(date.gettime()); depositcheckwindow(int customerindex) throws ioexception, parseexception{ //create make deposit button jbutton depositbutton = new jbutton ("make deposit"); depositbutton.setfont(new font("helvetica", font.bold, 12)); depositbutton.setopaque(false); depositbutton.setpreferredsize(new dimension(85, 22)); depositbutton.setforeground(new color(251, 125, 24)); bufferedimage buttonicon6 = imageio.read(new file("images/depositbtn.png")); depositbutton = new jbutton(new imageicon(buttonicon6)); depositbutton.setborderpainted(false); depositbutton.setfocuspainted(false); depositbutton.setcontentareafilled(false); // add listener make deposit button depositbutton.addactionlistener (new actionlistener () { public void actionperformed(actionevent e){ // retrieve value text field checkamount = (double) txtamt.getvalue(); //checkamount = double.parsedouble(txtamt.gettext()); //deposit checking account if (tolist.getselecteditem().tostring().equals("checking account")){ dtchecking += checkamount; joptionpane.showmessagedialog(null,"you have deposited " + checkamount+" checking account."); } //deposit savings account else if (tolist.getselecteditem().tostring().equals("savings account")){ dtsavings += checkamount; joptionpane.showmessagedialog(null,"you have deposited $" + checkamount+" savings account."); } //deposit soar account else if (tolist.getselecteditem().tostring().equals("soar account")){ dtsoar += checkamount; joptionpane.showmessagedialog(null,"you have deposited $" + checkamount+" soar account."); } try { calculatebalances(customerindex); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); } txtamt.settext(""); }}); //calculate new account balances void calculatebalances(int customerindex) throws ioexception { //calculate newcb - new savings account balance newcb = loaddata.accounts[customerindex].getcheckingacctbal() + dtchecking; //calculate newsb - new savings account balance newsb = loaddata.accounts[customerindex].getsavingsacctbal() + dtsavings; //calculate new sob - new soar account balance newsob = loaddata.accounts[customerindex].getsoaracctbal() + dtsoar; //call methods depositfunds(customerindex); savetransaction(); } //update account balances boolean depositfunds(int customerindex){ int = 0; try { //connect database connection conn = drivermanager.getconnection("jdbc:ucanaccess:///volumes/green grass/jsproject/prjtims_js/bank11.mdb"); statement stmt = conn.createstatement(); system.out.println("connected database ..."); string upprofile = "update tblaccount set checkingacctbal = '" +newcb+ "', savingsacctbal = '" +newsb+ "', soaracctbal = '" +newsob+ "' custid = '" +loaddata.accounts[i].getcustid()+ "'"; stmt.execute(upprofile); conn.close(); joptionpane.showmessagedialog(null, "accounts table updated successfully"); } catch( exception e ){ system.out.println("can't retrieve database connection: "+e); } return true; } //write transaction table void savetransaction(){ try { int transcount = 0; //connect database connection conn = drivermanager.getconnection("jdbc:ucanaccess:///volumes/green grass/jsproject/prjtims_js/bank11.mdb"); statement stmt = conn.createstatement(); system.out.println("connected database ..."); string intransaction = "insert tbltransaction (transcount,"+ "custid,"+ "transnum," + "transtype, "+ "transdate) "+ "values('"+transcount+"','"+ loaddata.accounts[i].getcustid()+"','"+transnum+"','"+transtype+"','"+ts+"')"; transcount++; stmt.execute(intransaction); conn.close(); joptionpane.showmessagedialog(null, "transaction table values inserted successfully"); } catch( exception e ){ system.out.println("can't retrieve database connection: "+e); } }
}
Comments
Post a Comment