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

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:

主站蜘蛛池模板: 贵港市| 襄樊市| 宁德市| 河源市| 惠水县| 邹平县| 和林格尔县| 崇礼县| 呈贡县| 鄂伦春自治旗| 娄底市| 上高县| 都安| 绵阳市| 行唐县| 芜湖县| 屏东市| 宁乡县| 称多县| 阿城市| 美姑县| 桦南县| 大新县| 科技| 马鞍山市| 马尔康县| 东乌| 北辰区| 莎车县| 迁西县| 蓬溪县| 西充县| 江孜县| 阳高县| 巴楚县| 潼南县| 定州市| 岫岩| 江孜县| 浏阳市| 抚远县|