[英]I'm making a payroll using Java. Why am I getting the wrong net pay if my mathematical formulas seem correct?
[英]I'm trying to update my password in oracle database using Java. Am I doing something wrong?
即使单击按钮更改密码,运行模拟器时也不会出现任何错误。 我已经尝试了所有可以想到的方法,有人知道我是否做错了什么。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_account);
更改密码的按钮
Button password = (Button) findViewById(R.id.btnChangePassword);
password.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
update();
} catch (Exception e) {
e.printStackTrace();
}
}
});}
密码更新方法
public Exception update()throws Exception{
Connection conn = null;
Statement st = null;
try {
conn = ConnectionManager.getConnection();
st = conn.createStatement();
String select_password = "SELECT * From Userinfo Where USERID = 5";
ResultSet Password = st.executeQuery(select_password);
String password = "UPDATE userinfo SET PASSWORD = ? WHERE USERID = 5";
while (Password.next()) {
PreparedStatement ps = null; //conn.prepareStatement(Update_Bank);
ps = conn.prepareStatement(password);
String pass = "password123";
ps.setString(1, pass);
ps.executeUpdate();
ps.close();
}
}catch(Exception e){
return e;
}
return null;
}}
好的,所以我做了一些修改,遍历了代码,发现它在“ ResultSet Password = st.executeQuery(select_password);”处失败。 声明。 问题是它可以在Eclipse中工作,但不能在android studio中工作。 有人对为什么有任何想法吗?
Connection conn = null;
Statement st = null;
conn = ConnectionManager.getConnection();
st = conn.createStatement();
String select_password = "SELECT * From Userinfo Where USERID = 5";
ResultSet Password = st.executeQuery(select_password);
String password =( "UPDATE userinfo SET PASSWORD = ? WHERE USERID = 5");
while (Password.next()) {
PreparedStatement ps = conn.prepareStatement(password);
ps = conn.prepareStatement(password);
String pass = "password";
ps.setString(1, pass);
ps.executeUpdate();
ps.close();
}
}
您不会有任何异常,因为您在update内有一个catch all语句,通过忽略update的返回值可以完全忽略它!
修复后,请执行以下操作:
确保while循环内的代码正在执行
检查executeUpdate的返回值是否大于0
如果不熟悉用于更改密码的SQL语法,您是否尝试过直接在控制台中运行它?
和一些建议:
您不需要查询,因为您没有使用它的结果集。
切勿使用ID。 请改用用户名。
关闭连接
切勿捕获所有异常。 如果这样做,则永远不要忽略何时引发异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.