- 浏览: 731289 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
though it's nearly impossible to find out whether it's possible to use such kind of designated parameter (:1) in PreparedStatement, it's possible, and have been proved true.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DemoResultSetOracle { public static Connection getConnection() throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:databaseName"; String username = "username"; String password = "password"; Class.forName(driver); // load Oracle driver Connection conn = DriverManager.getConnection(url, username, password); return conn; } public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); System.out.println("conn=" + conn); // prepare query String query = "select id, name, age from employees where xxx = (:1)"; // create a statement stmt = conn.createStatement(); // execute query and return result as a ResultSet rs = stmt.executeQuery(query); // extract data from the ResultSet while (rs.next()) { String id = rs.getString(1); String name = rs.getString(2); int age = rs.getInt(3); System.out.println("id=" + id); System.out.println("name=" + name); System.out.println("age=" + age); System.out.println("---------------"); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { // release database resources try { rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
using designated parameters would look like:
select id, name, age from employees where xxx = (:1)
发表评论
-
关于方法访问控制符protected
2012-11-29 10:38 1208http://bbs.csdn.net/topics/3902 ... -
一个基本问题关于引用的
2012-05-15 10:20 1090问: int a = 1; Integer b = new ... -
我對面向對象和過程的理解。
2012-05-02 08:30 1026我的一些理解。 面向过程,是对客观现象的描述,感觉是有一个上 ... -
stack and heap
2012-01-13 23:17 1024我觉得是根据应用方式 和本身特性 才将内存分区的,目的是提 ... -
program experience conclusion
2011-07-11 15:35 10251. check parameters for validit ... -
clean Log4j
2011-04-12 11:19 1034import org.apache.log4j.BasicCo ... -
about abstract class
2011-04-02 10:34 824yes, we do know abstract class ... -
cvs operations on linux
2011-03-25 09:40 969http://www.linuxhowtos.org/Syst ... -
regex to exchange two parts
2011-03-24 17:09 1020public class Test { public ... -
About the database locking
2011-03-09 11:02 909http://en.wikipedia.org/wiki/Lo ... -
how to send soap message in java
2011-03-08 10:29 1861import java.io.BufferedReader; ... -
About ShutDownDemo
2011-03-07 15:02 932public class ShutdownDemo { p ... -
How do you know if an explicit object casting is needed
2011-02-24 16:33 1133通俗来讲,不可能将一只是猫的动物强转为狗 再说Graphic ... -
有关MimeUtility
2011-02-24 13:11 3311import java.io.UnsupportedEncod ... -
C#连接sql server 2008的一件2事
2011-02-24 09:01 2121once upon a time, i came upon o ... -
Shadowing, Overriding, Hiding and Obscuring
2011-02-22 15:15 1109当子类属性与父类属性重叠时 这种叫法上是shadowi ... -
JAXP usage
2011-02-16 16:07 1061import java.io.ByteArrayInputSt ... -
运行一个类,如果classpath中路径带空格就加双引号
2011-02-11 11:25 2774注意是这样加: java -cp .;"d:\my ... -
关于ClassPath中的current directory
2011-01-28 16:40 1121Given: 1. package com.company. ... -
文件内容操作batch
2011-01-27 16:36 1171I've learnt it from csdn qybao( ...
相关推荐
jdbc2.0版 PreparedStatement接口的用法
Statement和PreparedStatement之间的区别 Statement和PreparedStatement是JDBC中的两种不同的语句对象,用于执行数据库操作。虽然它们都可以执行SQL语句,但是它们之间存在着很大的区别。 首先, Statement对象...
PreparedStatement详细用法
关于PreparedStatement插入Date类型值的方法.txt
JDBC基础教程之PreparedStatement.doc )
Java 中 PreparedStatement 和 Statement 的区别 Java 中的 PreparedStatement 和 Statement 都是用于执行 SQL 语句的接口,但是它们之间存在一些关键的区别。 首先,从数据库执行 SQL 语句的角度来看,使用 ...
NULL 博文链接:https://huiminchen.iteye.com/blog/1097332
在java中向访问数据库的sql语句一般放到类PreparedStatement类构造函数中,这里遇到的问题就是向sql语句中用setDate()插入时间时不能用java.util.date,而应用java.sql.date,这里就讲述了解决方法,一种是插入...
练习3:使用PreparedStatement插入宠物信息.zip
NULL 博文链接:https://chaoyi.iteye.com/blog/2088080
MySql练习3:使用PreparedStatement插入宠物信息.zip MySql练习3:使用PreparedStatement插入宠物信息.zip MySql练习3:使用PreparedStatement插入宠物信息.zip
可以了解PreparedStatemen的具体用法,使用与JSP初学者
NULL 博文链接:https://stevenjohn.iteye.com/blog/968877
JDBC 中 PreparedStatement 接口提供的 execute、executeQuery 和 executeUpdate 之间的区别及用法 JDBC 中的 PreparedStatement 接口提供了三种执行 SQL 语句的方法:executeQuery、executeUpdate 和 execute。...
此实例意在解决预处理命令PreparedStatement的setString()方法,在sql2008数据库中写入数据时,会自动补足空格的问题, 同时此实例也解决了当存在自动补足空格的问题时,使用nvarchar可以使查找出来的数据与原输入...
什么时候用statement,什么时候用preparedstatement
java.sql.PreparedStatement接口。PrepareStatement接口继承Statement接口。 PrepatredStatement实例包含已编译的SQL语句,由于PreparedStatement对象已预编译过哦哦,所以执行速度快于Statement对象。 包含于...
主要介绍了JSP中的PreparedStatement对象操作数据库的使用教程,文中举了一些使用PreparedStatement预处理语句对象进行MySQL增删查改的例子,需要的朋友可以参考下
jdbc中preparedStatement比Statement的好处