码迷,mamicode.com
首页 > 数据库 > 详细

数据库查找和删除

时间:2017-08-14 20:07:36      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:pack   ati   rate   otf   coding   parameter   unicode   res   rom   

package method;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
public class InsertDemo{
public ResultSet rs=null;
public static String JDBC_DRIVER = "com.mysql.jdbc.Driver";
public static String DB_URL = "jdbc:mysql://127.0.0.1:3306/school?useUnicode=true&characterEncoding=utf8";
// 数据库的用户名与密码,需要根据自己的设置
public static String USER = "root";
public static String PASS = "123456";
public static Connection con=null;
static{
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection(DB_URL, USER, PASS);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet getDate(HttpServletRequest request){
String sql = "select * from productmanage";
String id = request.getParameter("id");
String name = request.getParameter("name");
if(id!=null && !id.equals(""))
sql="select * from productmanage where 商品编号=‘"+id+"‘ and 商品名称 =‘"+name+"‘";
try {
PreparedStatement psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;

}
public void deleteMethod(HttpServletRequest res){
String chk[] = res.getParameterValues("chk");
String chkall="";
int delrec = 0;
System.out.println("deleteMethod run!!!!!!!");
if (chk!=null)
{
for(String i:chk)
{
String sql = "delete from productmanage where 商品编号 =?";
try {
PreparedStatement psmt = con.prepareStatement(sql);
psmt.setString(1, i);
delrec = psmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
System.out.println("you del rec="+delrec);
}

}
//执行sql语句
}

}


}

数据库查找和删除

标签:pack   ati   rate   otf   coding   parameter   unicode   res   rom   

原文地址:http://www.cnblogs.com/loveyoukk/p/7359729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!