您好我正在尝试创建一个包含用户的程序,每个用户都可以计算他的付款,因为他的每小时工资值以及他工作了多少小时。
我堆叠在按钮上,为特定用户增加了几个小时或更新
usernameGL - >全局变量(public static String usernameGL =“”;) Connect() - >方法(工作!)
我正在使用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 FROM Att WHERE Att.ID = users1.ID AND users1.username='" + usernameGL + "'";
result = state.executeQuery(SQL);
if (result.next()) {
hoursTable = result.getDouble("hours");
if (hoursTable == 0) {
SQL = "INSERT INTO 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 + ") WHERE hours = (" + hoursTable+")";
String hoursString = toString().valueOf(total);
currentTF.setText(hoursString);
}
}
} catch (SQLException f) {
}
}