java - stack on insert or update sql table on a user -
hello trying create program has users , each user can calculate payment due pay per hour value , how many hours has worked.
i stacked on button adds hours specific user or updates
usernamegl --> global variable (public static string usernamegl ="";) connect() --> method (workes!)
i using access db , java
private void addbt_actionperformed(actionevent e) { double hours1 = 0.0; double hourstable = 0.0; hours1 = double.parsedouble(joptionpane.showinputdialog(this, "how many hours did u work?", joptionpane.question_message)); //establish connection connect(); try { resultset result; statement state = conn.createstatement(); string sql = "select att.hours att att.id = users1.id , users1.username='" + usernamegl + "'"; result = state.executequery(sql); if (result.next()) { hourstable = result.getdouble("hours"); if (hourstable == 0) { sql = "insert att (hours) values (" + hours1+")"; result = state.executequery(sql); string hoursstring = tostring().valueof(hourstable); currenttf.settext(hoursstring); } else if (hourstable > 0) { double total = hourstable + hours1; sql = "update att set hours= (" + total + ") hours = (" + hourstable+")"; string hoursstring = tostring().valueof(total); currenttf.settext(hoursstring); } } } catch (sqlexception f) { } }
Comments
Post a Comment