我想删除数据库中包含.jpg扩展名所在的URL的所有行!
我正在使用
try{
java.sql.Statement mystat=connection.createStatement();
String delete_jpg="DELETE FROM mytable WHERE mycol LIKE '%.jpg%' ";
mystat.executeUpdate(delete_jpg);
}catch(Exception e){
}
使用Java JDBC执行此查询根本不会产生任何错误,但它也不会删除行!请有人告诉我,我做错了,请!!!
示例网址为:
images/affiliation-logo4.png HTTP/1.1
images/661.jpg HTTP/1.1
footerslider/images/blue-left-arrow.png HTTP/1.1
footerslider/images/blue-right-arrow.png HTTP/1.1
media/contentHeader/32.jpg HTTP/1.1 //I want to delete this type of rows
index.php?option=com_content&task=view&id=543 HTTP/1.1
images/favic.ico HTTP/1.1
src/ HTTP/1.0
uiit/faculty.php?dept_id=31 HTTP/1.1
uims/faculty.php?dept_id=32 HTTP/1.1
media/profile/dhS1t8X.jpg HTTP/1.1 //I want to delete this type of rows
media/profile/SSbkpgG.jpg HTTP/1.1 //I want to delete this type of rows
答案 0 :(得分:0)
您可以尝试对您的陈述进行此修改:
String delete_jpg="DELETE FROM mytable WHERE mycol LIKE '%' + .jpg + '%' ";
答案 1 :(得分:0)
从示例网址中我发现模式是:
media/profile/dhS1t8X.jpg HTTP/1.1 //I want to delete this type of rows
问题在于你做得对,但模式应该是:
try{
java.sql.Statement mystat=connection.createStatement();
String delete_jpg="DELETE FROM mytable WHERE mycol LIKE '%.jpg %' "; //HERE YOU HAVE TO ADD A WHITE SPACE AFTER THE .jpg as you can also seen in your sample URL!
mystat.executeUpdate(delete_jpg);
}catch(Exception e){
}
做到这一点,肯定会帮到你!