当前位置:Gxlcms > 数据库问题 > 数据库查找和删除

数据库查找和删除

时间:2021-07-01 10:21:17 帮助过:35人阅读

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   

人气教程排行