简体   繁体   English

无法在SQL Server 2008 R2上执行(删除)查询

[英]Unable to Execute a (DELETE) Query on SQL Server 2008 R2

I want to delete all the rows in the data base that contain the URL in which .jpg extension comes! 我想删除数据库中包含.jpg扩展名的URL的所有行!

I am using 我在用

 try{
 java.sql.Statement mystat=connection.createStatement();
 String delete_jpg="DELETE FROM mytable WHERE mycol LIKE '%.jpg%' ";
 mystat.executeUpdate(delete_jpg);
 }catch(Exception e){
  }

Executing this query using Java JDBC gives no errors at all but it is not deleting the rows as well! 使用Java JDBC执行此查询不会产生任何错误,但也不会删除行! Please can somebody tell me that what I'm doing wrong please!!! 请有人告诉我我做错了吗!!!!

Example URLs are: URL示例为:

 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

您可以尝试对语句进行以下修改:

String delete_jpg="DELETE FROM mytable WHERE mycol LIKE '%' + .jpg + '%' ";

As from your sample URLs I see that the pattern is: 从示例URL中,我看到模式是:

 media/profile/dhS1t8X.jpg HTTP/1.1     //I want to delete this type of rows

The thing is that you're doing correctly but the pattern should be like: 问题是您做得正确,但是模式应该像这样:

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){
}

Do it and will definitely help you! 做到这一点,一定会帮助您!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM