[英]I'm trying to update my password in oracle database using Java. Am I doing something wrong?
I am not getting any errors when running the emulator even when clicking on the button to change the password.
即使单击按钮更改密码,运行模拟器时也不会出现任何错误。 I've tried everything I can think of does anyone know if i'm doing something wrong.
我已经尝试了所有可以想到的方法,有人知道我是否做错了什么。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_account);
Button to change password
更改密码的按钮
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();
}
}
});}
Method to Update Password
密码更新方法
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;
}}
Ok so I changed some things up and I ran through the code and found it is failing at the "ResultSet Password = st.executeQuery(select_password);"
好的,所以我做了一些修改,遍历了代码,发现它在“ ResultSet Password = st.executeQuery(select_password);”处失败。 statement.
声明。 The thing is it works in eclipse but not in android studio.
问题是它可以在Eclipse中工作,但不能在android studio中工作。 Anyone have any thoughts of why?
有人对为什么有任何想法吗?
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();
}
}
You won't get any exceptions because you have a catch all statement inside update which you completely ignore by ignoring the return value of update! 您不会有任何异常,因为您在update内有一个catch all语句,通过忽略update的返回值可以完全忽略它!
After fixing that do the following: 修复后,请执行以下操作:
Make sure that the code inside the while loop is getting executed 确保while循环内的代码正在执行
Check that the return value of executeUpdate is greater than 0 检查executeUpdate的返回值是否大于0
In not familiar with this SQL syntax for changing password, have you tried running it directly in the console? 如果不熟悉用于更改密码的SQL语法,您是否尝试过直接在控制台中运行它?
And a few bits of advice: 和一些建议:
You don't need the query since you are not using it's result set. 您不需要查询,因为您没有使用它的结果集。
Never use IDs. 切勿使用ID。 Use the user's name instead.
请改用用户名。
Close the connection 关闭连接
Never catch all Exceptions. 切勿捕获所有异常。 If you do, never ever ignore when an exception is thrown.
如果这样做,则永远不要忽略何时引发异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.