java のcallableStatementを実行したところエラーが発生します。
どうしたら解決するでしょうか?
package sample;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class test {
public static void main(String[] args) {
Connection conn =null;
Statement stmt=null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/sample", "root", "password");
String query = "{call test1(?,?)}";
CallableStatement callablestmt= conn.prepareCall(query);
callablestmt.setInt(1, 7);
callablestmt.registerOutParameter(2, java.sql.Types.INTEGER);
callablestmt.execute(query); //System.out.println(callablestmt.getInt(2)); } catch(Exception ex) { System.out.println("エラー発生"); } }
}
エラー内容は
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?)' at line 1
です。
引数に値を入れたのcallablestatementは実行できます。
String query = "{call test1(1)}"; このような感じのもの
なので変数をセットしているあたりだとは思うのですが。。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/11/08 12:55