[英]Running a stored procedure from Java using Statement Execute?
我的Java代碼去了
Statement statement = connection.createStatement();
String storedProc = "exec stored_proc(" + someVariable + ")";
statement.execute(storedProc);
但是Java拋出SQLSyntaxException。 知道我在做什么錯嗎?
試試這個查詢:
在當前方法中,您可以使用:
String storedProc = "{call stored_proc(" + someVariable + ")}";
請注意,我使用了call
而不是exec
,並且用大括號包圍了查詢。
但為避免sql injection
您可以使用參數化查詢,例如:
String storedProc="{call stored_proc(?)}";
PreparedStatement pstmt=connection.prepareStatement(storedProc);
pstmt.setString(1,someVariable);
pstmt.execute(storedProc);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.