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

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:

主站蜘蛛池模板: 沙湾县| 彭水| 罗甸县| 河池市| 高阳县| 洪湖市| 乌鲁木齐县| 黄大仙区| 翁源县| 鸡泽县| 海盐县| 凤冈县| 英超| 东城区| 崇信县| 当阳市| 阳信县| 长泰县| 喜德县| 玛沁县| 石家庄市| 富民县| 栾川县| 平罗县| 远安县| 曲靖市| 翁源县| 兰溪市| 洛川县| 板桥市| 迁西县| 西吉县| 玛曲县| 遂溪县| 寻乌县| 六盘水市| 孝感市| 宁城县| 丹凤县| 禹城市| 称多县|