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

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:

主站蜘蛛池模板: 溧水县| 桃园市| 大悟县| 交口县| 黄石市| 安义县| 兰州市| 大化| 海晏县| 灵丘县| 合阳县| 潞西市| 英德市| 肥东县| 张北县| 房产| 白城市| 连山| 鲁甸县| 荥阳市| 唐海县| 义马市| 遵化市| 五华县| 搜索| 永定县| 蓝田县| 曲水县| 巴林左旗| 安远县| 衡阳市| 绥江县| 同心县| 丰台区| 黄大仙区| 平乐县| 姚安县| 讷河市| 太原市| 陵川县| 龙胜|