PreparedStatement
来源:互联网 发布:解决网络高峰期问题 编辑:程序博客网 时间:2024/05/17 01:48
/*
* preparedstatement
* 1.PreparedStatement 可以提高执行效率(因为他有预编译功能)
* 2.PreparedStatement 可防止sql注入漏洞
*/
import java.sql.*;
public class test2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PreparedStatement ps=null;
ResultSet rs=null;
Connection ct=null;
try {
//加载驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//得到连接
ct=DriverManager.getConnection("jdbc:odbc:mytest");
//创建ps
// ps=ct.prepareStatement("select * from dept where deptno=?");
// ps.setInt(1,50);
// rs=ps.executeQuery();
//
// while(rs.next()){
//
// System.out.print(rs.getInt(1)+rs.getString(2));
// }
ps=ct.prepareStatement("insert into dept values(?,?,?)");
ps.setInt(1,20);
ps.setString(2,"60");
ps.setString(3,"love");
int i=ps.executeUpdate();
if(i==1)
{
System.out.println("insert ok\n");
}
else {
System.out.println("insert error\n");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
try {
//关闭资源
if(rs!=null){
}
ps.close();
if(ct!=null){
ct.close();
}
} catch (Exception e2) {
// TODO: handle exception
// e2.printStackTrace();
}
}
}
}
* preparedstatement
* 1.PreparedStatement 可以提高执行效率(因为他有预编译功能)
* 2.PreparedStatement 可防止sql注入漏洞
*/
import java.sql.*;
public class test2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PreparedStatement ps=null;
ResultSet rs=null;
Connection ct=null;
try {
//加载驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//得到连接
ct=DriverManager.getConnection("jdbc:odbc:mytest");
//创建ps
// ps=ct.prepareStatement("select * from dept where deptno=?");
// ps.setInt(1,50);
// rs=ps.executeQuery();
//
// while(rs.next()){
//
// System.out.print(rs.getInt(1)+rs.getString(2));
// }
ps=ct.prepareStatement("insert into dept values(?,?,?)");
ps.setInt(1,20);
ps.setString(2,"60");
ps.setString(3,"love");
int i=ps.executeUpdate();
if(i==1)
{
System.out.println("insert ok\n");
}
else {
System.out.println("insert error\n");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
try {
//关闭资源
if(rs!=null){
}
ps.close();
if(ct!=null){
ct.close();
}
} catch (Exception e2) {
// TODO: handle exception
// e2.printStackTrace();
}
}
}
}
- preparedstatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- preparedstatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- PreparedStatement
- ARM linux hard soft irq
- Python食谱-1.2.字符与数字编码之间的互换
- 为Adobe reader添加书签功能
- MyC++系列:1、系统总结1
- Debian下编译、运行和调试C++程序
- PreparedStatement
- ubuntu 11.10 创建桌面快捷方式
- statement
- 个人职业规划篇
- 设计原理本质
- HDU 1203
- jadEclipse svn myeclipse中 安装方法
- 宇宙蘑菇
- 用文字记录自己感悟,用博客见证自己的成长,用编程成就自己的梦想