package com.bzq.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.bzq.model.UserModel;
public class DeleteDao {
public static int deleteMode=-1;
public static void main(String[] args) {
}
public static void delete(UserModel um) {
//用来连接oracle数据库
Connection connection=null;
//执行SQL语句
PreparedStatement preparedStatement=null;
try {
//加载数据库驱动
Class.forName("oracle.jdbc.OracleDriver");
//数据库地址jdbc:oracle:thin:@localhost:数据库端口号:数据库SID
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//数据库用户名和密码
String userName="system";
String userPassword="088413";
connection=DriverManager.getConnection(url,userName,userPassword);
//sql语句,?代表动态赋值
String strSql="delete users where id=?";//,sex=?,age=?,password=?
System.out.println(strSql);
//执行sql语句
preparedStatement=connection.prepareStatement(strSql);
System.out.println("dao:"+um.getId());
preparedStatement.setString(1,um.getId());
// preparedStatement.setString(2,um.getSex());
// preparedStatement.setString(3,um.getAge());
//提交sql语句到数据库insertMode=
deleteMode=preparedStatement.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally {
try {
connection.close();
preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
// public static String StrSql(UserModel um){
// String n=um.getName();
// String s=um.getSex();
// String a=um.getAge();
//
//
// String strSql=null;
// if ((n!="")&&(s!="")&&(a!="")) {
// strSql="delete users where name=? and sex=? and age=?";
// }
// if ((n!="")&&(s!="")&&(a=="")) {
// strSql= "delete users where name=? and sex=?";
// }
// if ((n!="")&&(s=="")&&(a!="")) {
// strSql= "delete users where name=? and age=?";
// }
// if ((n=="")&&(s!="")&&(a!="")) {
// strSql="delete users where sex=? and age=?";
// }
// if ((n!="")&&(s=="")&&(a=="")) {
// strSql= "delete users where name=?";
// }
// if ((n=="")&&(s!="")&&(a=="")) {
// strSql= "delete users where sex=?";
// }
// if ((n=="")&&(s=="")&&(a!="")) {
// strSql= "delete users where age=?";
// }
//
// return strSql;
//
// }
}
评论0
最新资源