官术网_书友最值得收藏!

PreparedStatement Interface

A PreparedStatement object represents a precompiled SQL statement. The PreparedStatement interface extends the Statement interface. The precompiled SQL statement has IN parameters for which values are being set with the setter methods of the PreparedStatement interface. A 'setter' method is included for each of the Java data types that map to a SQL data type. The JDBC driver converts the Java data type to an SQL data type. The IN parameter values are set with parameter index. For example, update a Catalog table with the following definition using PreparedStatement :

CatalogId NUMBER Journal VARCHAR(255) Publisher VARCHAR(255) Title VARCHAR(255) Author VARCHAR(255) 

Set Publisher column value to Oracle Publishing, and Journal column values to Oracle Magazine, where CatalogId is 1, referred to the code below:

PreparedStatement pstmt = connection.prepareStatement("UPDATE CATALOG SET Journal=? AND Publisher=? WHERE CatalogId=?");
pstmt.setString(1, "Oracle Magazine");
pstmt.setString(2, "Oracle Publishing");
pstmt.setInt(3, 1);
pstmt.executeUpdate();

If the database supports statement pooling, PreparedStatement objects are pooled by default. In JDBC 4.0, the methods discussed in the following table have been added to the PreparedStatement interface:

主站蜘蛛池模板: 县级市| 西宁市| 嘉荫县| 襄汾县| 当雄县| 怀宁县| 诸暨市| 福安市| 澄迈县| 黑山县| 安岳县| 台东县| 郧西县| 台北市| 永靖县| 徐水县| 广丰县| 博兴县| 新田县| 贵南县| 阿瓦提县| 吴桥县| 蓬溪县| 龙游县| 墨江| 白沙| 无锡市| 日土县| 蕲春县| 巫溪县| 宁德市| 涟源市| 米脂县| 克什克腾旗| 金塔县| 灵川县| 巩义市| 平顶山市| 肥东县| 乐平市| 邳州市|