Class UtiDb
Class Book
Class CallebalSta
package JavaJDBC.Chap07.sec02;
import JavaJDBC.util.UtiDb;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
/**
* Created by linux_ccmj on 16-5-16.
*/
public class CallableSta {
// utiDb
private static UtiDb utiDb = new UtiDb();
// Get book info by book id
private static String getBooNamFun(int id) throws Exception {
// Connection, sql command string
Connection con = utiDb.getConFun();
String strComSql = "Call proGetBooNam(?, ?)";
// Callabelstatement
CallableStatement calSta = con.prepareCall(strComSql);
calSta.setInt(1, id);
calSta.registerOutParameter(2, Types.VARCHAR);
calSta.execute();
String namBoo = calSta.getString("namBoo");
// Close
utiDb.clsConFun(calSta, con);
// Return
return namBoo;
}
// Test main
public static void main(String[] args) throws Exception {
String namBoo = getBooNamFun(11);
System.out.println("Book Name: "+namBoo);
}
}