PreparedStatement的使用----JDBC-2
来源:互联网 发布:植发失败 知乎 编辑:程序博客网 时间:2024/06/05 02:52
今天可是双十二,各种超市五折,各种支付宝结算五折,而苦逼的我还在这里写博客。。。
谁让我是一只程序员,重点是还单身
言归正传,今天说的是PreparedStatement,它是Statement的子接口,其作用也和Statement一样,但是有不少优点:
总结:PreparedStatement VS Statement
1.简化程序
2.防止SQL注入
3.提高性能
大家刚学JDBC的时候是不是老是在拼写sql语句时出现错误,而且不易发现,搞得大家很头疼。
今天这个PreparedStatement就可以大大减轻我们的工作量还不容易出错,具体请看代码!
/** *@author HelloWorld 2015/12/12 * */ @Testpublic void testPreparedStatement() {Connection connection = null;PreparedStatement preparedStatement = null;try {//获取数据库链接,具体方法可以查看往期博文connection = getConnection();//向oracle数据库中的customer表插入数据String sql ="insert into customer (id,name ,email ,birth)" +"values(customer_seq.nextval,?,?,?)";preparedStatement = connection.prepareStatement(sql);preparedStatement.setString(1, "charles");preparedStatement.setString(2, "479846@fejifje");preparedStatement.setDate(3, new Date(new java.util.Date().getTime()));preparedStatement.executeUpdate();} catch(Exception e) {e.printStackTrace();} finally {//关闭相应的资源if(preparedStatement != null) {try {preparedStatement.close();} catch (Exception e) {e.printStackTrace();} }if(connection != null) {try {connection.close();} catch (Exception e) {e.printStackTrace();} }}}
1 0
- PreparedStatement的使用----JDBC-2
- jdbc PreparedStatement 的使用
- JDBC 连接数据库 PreparedStatement的使用
- JDBC入门教程(三) PreparedStatement的使用
- JDBC中PreparedStatement接口的使用
- jdbc preparedstatement 使用
- JDBC使用PreparedStatement好处
- JDBC的PreparedStatement用法
- JDBC使用 PreparedStatement 比使用 Statement 的好处
- JDBC中使用PreparedStatement语句
- 如何使用JDBC的PreparedStatement类的setClob()方法
- 封装JDBC,简单快捷的使用PreparedStatement对象
- JDBC使用PreparedStatement而不是Statement的原因(转)
- JDBC的PreparedStatement启动事务使用批处理executeBatch()
- JDBC中PreparedStatement与Statement的区别与使用
- JDBC的PreparedStatement启动事务使用批处理executeBatch()
- JDBC中Statement、PreparedStatement和CallableStatement的使用
- JDBC中使用preparedStatement相比statement的优势
- Java面向对象知识总结
- android获取联系人权限,然后从日志中打印输出联系人姓名和电话
- ousahayashi's array practice!
- hdu1040 As Easy As A+B
- 校赛Round1 1004 防AK的数字
- PreparedStatement的使用----JDBC-2
- 黑马程序员--C语言自学笔记---02基础语法
- [012]微信公众号开发教程第3篇--群发图文消息里图片被过滤掉的问题
- HTML5之javascript(一)
- 归并排序(merge Sort)
- 关于js中取非行间样式的兼容问题
- JAVA压缩图片
- [Oracle] 逻辑结构实验与总结
- C/C++程序员学习路线