jdbc怎么执行存储过程

Javaでストアドプロシージャを実行するには、JDBCのCallableStatementオブジェクトを使用します。以下はストアドプロシージャを実行するサンプルコードです。

“`java
// 接続の確立
Connection connection = DriverManager.getConnection(url, username, password);

// ストアドプロシージャの呼び出し用ステートメントの準備
String sql = “{call stored_procedure_name(?, ?)}”;
CallableStatement statement = connection.prepareCall(sql);

// ストアドプロシージャのパラメータの設定
statement.setString(1, parameter1);
statement.setInt(2, parameter2);

// ストアドプロシージャの実行
statement.execute();

// ストアドプロシージャの出力パラメータの取得
String output = statement.getString(3);

// 接続とステートメントのクローズ
statement.close();
connection.close();
“`

上記のサンプルコードでは、`url`、`username`、`password`、`stored_procedure_name`、およびパラメータの値を実際の値に置き換えてください。

bannerAds