1

My Java code goes

Statement statement = connection.createStatement();
String storedProc = "exec stored_proc(" + someVariable + ")";
statement.execute(storedProc);

But Java throws an SQLSyntaxException. Any idea what I am doing wrong?

1 Answer 1

2

Try this query:

In your current approach you can use:

String storedProc = "{call stored_proc(" + someVariable + ")}";

Note that I have used call instead of exec, and I have surrounded query with curly braces.

But to avoid sql injection you can use parametrised query like:

String storedProc="{call stored_proc(?)}";
PreparedStatement pstmt=connection.prepareStatement(storedProc);
pstmt.setString(1,someVariable);
pstmt.execute(storedProc);
Sign up to request clarification or add additional context in comments.

2 Comments

how can i change this 'EXEC spGetCustomerDetails 123455789'
@R.Anandan I didn't get your point, please ask a separate question or explain your question in detail here.

Your Answer

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.