代码如下
            PreparedStatement preState = conn.prepareStatement( "ALTER USER \"?\" IDENTIFIED BY \"?\" REPLACE \"?\"");
            preState.setString(1, this.userId);
            preState.setString(2, newPassword);
            preState.setString(3, this.password);
            logger.debug("User" + this.userId + " NewPassword"+newPassword+" OldPassword:"+ this.password+"\nSQL:"+sql);
            preState.execute();
            preState.close();
            preState = null;运行时总是提示:
Unable to change password, exception occurs java.sql.SQLException: ORA-01918: user ':1' does not exist

解决方案 »

  1.   

    SQL 异常  user ':1' does not exist 不存在 参数没替换掉吧
      

  2.   

    preState.setString(1, this.userId); 这一段就是替换第一个参数 user的啊
      

  3.   

      "ALTER USER \"?\" IDENTIFIED BY \"?\" REPLACE \"?\"";
    这条语句 修改表结构?
      

  4.   

    额  更改密码的.这个preState 能打印sql么
      

  5.   

    "ALTER USER \"?\" IDENTIFIED BY \"?\" REPLACE \"?\"" 换成 update之类的语句是成功的 就是alter的时候貌似传参有问题
      

  6.   

    Unable to change password, exception occurs java.sql.SQLException: ORA-01918: user ':1' does not exist
    很明显你传入的参数this.userId=1,报错说的1这个用户不存在
      

  7.   

    想要相关语言的所有资料吗?java,c++,c#,html,javascript,javaweb,sqlserver,oracle,jquery,Linux,等等等等,程序员必备的学习资料,快来看看吧。
    我的压缩包里面不止一两样东西哦,那可是我学习和工作的所有资料,不管是学习还是工作都会需要。
    http://download.csdn.net/user/yangtonghai
      

  8.   

    一把我们用PreparedStatement 都用的executeUpdate()或executeQuery执行啊。。
    你这里是ALTER更改,那应该是executeUpdate()才对啊preState.execute()这种情况是在用Statement查询的时候执行用的, ,,你好像执行方法没有用对。你看看。。你用查询的方法去执行ALTER更改的操作所以会报错。参数有问题因为驱动程序执行时,按照查询的语法来执行的
      

  9.   

    我传成实际的字符串比如setString(1,"SDFSF");他也是报 ':1'用户不存在。
      

  10.   

     executeUpdate只执行 insert ,update,delete的操作吧。  和execute 都报一样的错误,我都尝试过了
      

  11.   

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import javax.naming.InitialContext;public class Main {  public static void main(String[] args) throws Exception {
        try {
          String url = "jdbc:odbc:databaseName";
          String driver = "oracle.jdbc.driver.OracleDriver";
          String user = "guest";
          String password = "guest";
          Class.forName(driver).newInstance();
          //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@10.189.217.110:1521:ftcgde","username","pwd");
          String changeLastName =  "ALTER USER \"?\" IDENTIFIED BY \"?\" REPLACE \"?\"";
          //String changeLastName =  "update table set name = ? where name = ?";
          PreparedStatement updateLastName = connection.prepareStatement(changeLastName);      updateLastName.setString(1, "username"); // Set lastname placeholder value
          updateLastName.setString(2, "newpwd"); // Set author ID placeholder value
          updateLastName.setString(3, "oldpwd");
          updateLastName.executeUpdate(); // execute the update
          //System.out.println("Rows affected: " + rowsUpdated);
          connection.close();
        } catch (ClassNotFoundException cnfe) {
          System.err.println(cnfe);
        } catch (SQLException sqle) {
          System.err.println(sqle);
        }
      } 大家可以拿这个回自己机器上试试
      

  12.   

     只要是alter语句 就报 ':1'用户错误,如果是update语句则顺利通过
      

  13.   

    ALTER 是修改表结构 
    UPDATE 是修改表里的数据
    完全2个意思~~
      

  14.   


    alter user  不也是一种 sql么 用execute 是可以执行任意的sql吧
      

  15.   

    insert into biao values(?,?,?,?)
    update biao set a=?, b=?
    select /delete from biao where a=? and b like ? and c>?只有这些?的地方可以用绑定变量只要是ddl就不可能用绑定变量了,直接拼接SQL
      

  16.   

     我猜也是这么回事,但是硬拼SQL 怎么防止SQL Injection啊。