代码如下
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
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
这条语句 修改表结构?
很明显你传入的参数this.userId=1,报错说的1这个用户不存在
我的压缩包里面不止一两样东西哦,那可是我学习和工作的所有资料,不管是学习还是工作都会需要。
http://download.csdn.net/user/yangtonghai
你这里是ALTER更改,那应该是executeUpdate()才对啊preState.execute()这种情况是在用Statement查询的时候执行用的, ,,你好像执行方法没有用对。你看看。。你用查询的方法去执行ALTER更改的操作所以会报错。参数有问题因为驱动程序执行时,按照查询的语法来执行的
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);
}
} 大家可以拿这个回自己机器上试试
UPDATE 是修改表里的数据
完全2个意思~~
alter user 不也是一种 sql么 用execute 是可以执行任意的sql吧
update biao set a=?, b=?
select /delete from biao where a=? and b like ? and c>?只有这些?的地方可以用绑定变量只要是ddl就不可能用绑定变量了,直接拼接SQL