getprice.java

来自「此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作」· Java 代码 · 共 31 行

JAVA
31
字号
package procedures;

import java.sql.*;
import connections.*;
import java.util.*;

public class GetPrice {
  public static void main(String[] args) {
    Connection conn = null;
    CallableStatement stmt = null;
    try {
      conn = ConnectionFactory.getConnection();

      String sql = "{ ? = call get_price(?) }";
      stmt = conn.prepareCall(sql);
      stmt.setInt(2, Integer.parseInt(args[0]));
      stmt.registerOutParameter(1, Types.DOUBLE);

      stmt.executeUpdate();
      //if no exception is thrown, the update succeeded
      System.out.println("Price is " + stmt.getDouble(1));
    } catch (Exception e) {
      System.out.println("GetPrice failed");
      e.printStackTrace();
    } finally {
      ConnectionFactory.close(stmt);
      ConnectionFactory.close(conn);
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?