Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在尝试使用Java更新oracle数据库中的密码。我做错什么了吗?_Java_Database - Fatal编程技术网

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

我正在尝试使用Java更新oracle数据库中的密码。我做错什么了吗?,java,database,Java,Database,运行emulator时,即使单击按钮更改密码,我也没有收到任何错误。我想尽一切办法都试过了,有人知道我做错了什么吗 更改密码的按钮 更新密码的方法 好的,我修改了一些内容,运行了代码,发现结果集Password=st.executeQueryselect\u Password失败;陈述问题是它可以在eclipse中工作,但不能在android studio中工作。有人知道为什么吗 您不会得到任何异常,因为在update中有一个catch-all语句,通过忽略update的返回值,您可以完全忽略它

运行emulator时,即使单击按钮更改密码,我也没有收到任何错误。我想尽一切办法都试过了,有人知道我做错了什么吗

更改密码的按钮

更新密码的方法

好的,我修改了一些内容,运行了代码,发现结果集Password=st.executeQueryselect\u Password失败;陈述问题是它可以在eclipse中工作,但不能在android studio中工作。有人知道为什么吗


您不会得到任何异常,因为在update中有一个catch-all语句,通过忽略update的返回值,您可以完全忽略它

修复后,请执行以下操作:

确保执行while循环中的代码

检查executeUpdate的返回值是否大于0

在不熟悉更改密码的SQL语法的情况下,您尝试过吗 直接在控制台中运行它

还有几点建议:

您不需要查询,因为您没有使用它的结果集

永远不要使用ID。改用用户名

关闭连接

永远不要抓住所有的例外。如果是这样的话,永远不要忽略抛出异常的情况

@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;
}}
    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();
    }

}