To do so, define a new PreparedStatement by writing the SELECT query as appropriate.
为此,可以相应地编写SELECT查询来定义一条新的PreparedStatement。
In this example, you first define the PreparedStatement as you did earlier in Listing 2.
在本例中,首先像先前在清单2中所做的一样定义PreparedStatement。
By using a PreparedStatement, you can dynamically modify your SQL statement at run time.
通过使用PreparedStatement,可以在运行时动态修改sql语句。
The following code snippets show the differences when using a Statement and a PreparedStatement.
下面的代码片段显示使用Statement与使用PreparedStatement的不同之处。
With the ij tool, you can accomplish this by using the REMOVE command to remove the PreparedStatement.
通过ij工具,可以使用REMOVE命令删除PreparedStatement 来完成此过程。
As shown in this example, you can also create a PreparedStatement to perform dynamic queries by using the ij tool.
如本例中所示,还可以创建一条PreparedStatement来使用ij工具执行动态查询。
In this article, you learned how to more effectively use PreparedStatement objects to support more advanced queries.
在本文中,您了解了如何更有效地使用PreparedStatement对象来支持更高级的查询。
You may have noticed that Listing 6 never executes the PreparedStatement that you constructed for the SQL UPDATE command.
您可能已经注意到清单6从未执行您为SQLUPDATE 命令构造的PreparedStatement。
Finally, you learned about the ParameterMetaData object and how it can be used to obtain metadata about different PreparedStatement parameters.
最后,了解了ParameterMetaData对象以及它可以怎样用于获得各种PreparedStatement参数的元数据。
If you try to reuse this PreparedStatement after it's been removed, an error is generated because the internal resources are no longer available.
如果尝试在删除后重用这条PreparedStatement,将生成错误,因为内部资源不再可用。
This included using the ij tool to prepare, execute, and remove a PreparedStatement, which can be useful when you're prototyping different approaches.
这包括了使用ij工具准备、执行和删除PreparedStatement,它们会在构建不同方法的原型时十分有用。
Both statements can use the PreparedStatement syntax (see Resources) of "? "for a parameter, in which case the username will be set for every parameter.
这两条语句都可以使用带“?”的preparedstatement语法作为一个参数(请参见参考资料),在这种情况下,将为每个参数设置用户名。
The variant with the PreparedStatement is more elegant regarding the coding, as no string arithmetic is required to put the values for STATE and TYPE in the SQL statement.
使用 PreparedStatement 的那种代码片段在编码方面更为优雅,因为在将STATE和TYPE的值置入SQL语句时,不需要进行字符串运算。
When you're done using a PreparedStatement object, you need to inform that database that the internal database resources allocated for the PreparedStatement can be released.
使用PreparedStatement对象完成操作后,需要通知该数据库分配给PreparedStatement的内部数据库资源可以释放了。
The opposite is true: PreparedStatement is recommended when a simple statement is executed many times with different values because the statement has to be compiled only once.
相反,如果要反复执行多次一条简单的语句,并且每次使用不同的值执行,建议使用PreparedStatement,因为语句只需编译一次。
The SQL Maps framework will create a PreparedStatement instance, set any parameters using the provided parameter object, execute the statement, and build a result object from the ResultSet.
SQLMaps框架将创建一个PreparedStatement实例,使用所提供的参数对象设置所有参数、执行语句以及从ResultSet中构建一个结果对象。
On the other hand, creating a PreparedStatement object introduces a certain amount of overhead, so, ideally, the statement's lifetime will be sufficiently long to compensate for this overhead.
在另一个方面,建立一个PreparedStatement对象会带来一定量的系统开销。所以,在理想情况下,这条语句的生命周期应该足够长,以补偿它所带来的系统开销。
On the other hand, creating a PreparedStatement object introduces a certain amount of overhead, so, ideally, the statement's lifetime will be sufficiently long to compensate for this overhead.
在另一个方面,建立一个PreparedStatement对象会带来一定量的系统开销。所以,在理想情况下,这条语句的生命周期应该足够长,以补偿它所带来的系统开销。
应用推荐