简体   繁体   English

我正在尝试使用Java更新oracle数据库中的密码。 难道我做错了什么?

[英]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.

相关问题 我正在使用 Java 制作工资单。 如果我的数学公式看起来是正确的,为什么我会得到错误的净工资? - I'm making a payroll using Java. Why am I getting the wrong net pay if my mathematical formulas seem correct? 我正在用Java中的“ 0”替换Evens,我在做什么错? - I am trying to replaceEvens with a “0” in java, what am I doing wrong? Java的Euler挑战1-我做错了什么? - Euler Challenge 1 in Java - I'm doing something wrong? 尝试使用Java查找GCD。 我在逻辑上坚持做某些事情 - Trying to find the GCD using java. I am stuck on some things with my do while logic 我的try-catch代码块做错什么了吗? - Am I doing something wrong with my try-catch block? Java的一些基本数学函数对初学者有问题。 我做错了什么吗? - Having a beginner issue with some basic math functions in Java. Anything I'm doing wrong? 无法在java中读取char数组。 我究竟做错了什么? - Trouble reading a char array in java. What am I doing wrong? 尝试使用班级中的一种方法打印出ArrayList,我在做什么错? - Trying to print out my ArrayList using one of my methods in my class what am i doing wrong? Tomcat maxthreads,我做错了什么吗? - Tomcat maxthreads, am I doing something wrong? 编译器中的错误或我做错了什么? - Bug in compiler or am I doing something wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM