1

I have a database Oracle 12 and query 'ALTER USER GISDPFB SET DEFAULT TABLESPACE DEV_MDS' Query is correct and i can execute it manually,but I can't to set parameters dynamically. My Code:

 callableStatement = connection.prepareCall("ALTER USER ? DEFAULT TABLESPACE ?");
 callableStatement.setString(1,"John");
 callableStatement.setString(2,"SYSAUX");
 callableStatement.execute();

I got 'java.sql.SQLSyntaxErrorException: ORA-01935: missing user or role name'

I guess this exception because of wrong syntax,but i have success when do it in console

2 Answers 2

3

You can only use bind variables for values, not identifiers - which both the user name and tablespace name are. You'll need to embed them in the statement:

callableStatement = connection.prepareCall("ALTER USER \"John\" DEFAULT TABLESPACE \"SYSAUX\"");
callableStatement.execute();

or if the values are coming from Java variables:

callableStatement = connection.prepareCall("ALTER USER \"" + userName
 + "\" DEFAULT TABLESPACE \"" + tablespaceName + "\"");
callableStatement.execute();

If they are from variables you might want to look at adding dbms_assert checks.

answered Feb 28, 2021 at 16:56
Sign up to request clarification or add additional context in comments.

Comments

0

I'm pretty sure ALTER USER is considered DLL and doesn't take bind variables. You'll probably have to just create a string for it. Try:

callableStatement = connection.prepareCall("ALTER USER john DEFAULT TABLESPACE SYSAUX");
callableStatement.execute();
answered Feb 28, 2021 at 17:05

2 Comments

can you give me advice,what kind of query you would use for my case for Oracle?I need to use bind variables(?,?)
You could check out this answer, by essentially wrapping the ALTER USER in EXECUTE IMMEDIATE. I haven't verified that it works. stackoverflow.com/questions/10315170/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.