0

我使用 txt 文件将数据上传到 mysql 数据库。我使用的txt文件如下:

http://www.repubblica.it/
http://www.repubblica.it/minify/sites/repubblica/nazionale/config_01.cache.php?name=site_home_css
http://www.repubblica.it/minify/sites/repubblica/nazionale/config_01.cache.php?name=social_home_css
http://quotidiano.repubblica.it/home?adv=t&source=homerepit
http://www.repubblica.it/servizi/mobile/index.html
http://inchieste.repubblica.it/
http://espresso.repubblica.it/
http://altoadige.gelocal.it/
http://corrierealpi.gelocal.it/
http://gazzettadimantova.gelocal.it/
http://gazzettadimodena.gelocal.it/
http://gazzettadireggio.gelocal.it/
http://mattinopadova.gelocal.it/
http://ilpiccolo.gelocal.it/
http://trentinocorrierealpi.gelocal.it/
http://lacittadisalerno.gelocal.it/

在我的 java 程序中,我使用以下 mysql 代码上传 txt 文件:

//here I create the table
CREATE TABLE table(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,url VARCHAR(1000) NOT NULL);"

//here the txt is loaded
LOAD DATA LOCAL INFILE \'/tmp/test/url.txt\' INTO TABLE table LINES (url)

一切正常。我的表有两列:id 和 url。 在此处输入图像描述

当我尝试使用简单的方法在该表中搜索一个值时:

SELECT url FROM table WHERE url LIKE 'http://www.repubblica.it/'

或者

SELECT url FROM table WHERE url ='http://www.repubblica.it/'

MySQL 返回一个空的结果集(即零行)。(查询耗时 0.0004 秒)这里是 phpmyadmin 的截图: 喜欢

平等的 为什么我无法寻找我的价值观?我做错了什么?提前致谢

4

2 回答 2

0

也许你在字符串前后有空格,试试这个:

UPDATE `table`
SET `url`=TRIM(`url`)

然后:

SELECT 
  `url` 
FROM 
  `table` 
WHERE 
  `url`='http://www.repubblica.it/'
于 2013-06-05T14:42:23.617 回答
0

您需要在 like 语句中使用通配符LIKE '%..%'来匹配字符串的一部分

SELECT url FROM table WHERE url LIKE '%http://www.repubblica.it/%'

如果您尝试直接搜索,phpmysqmin则可以选择按“LIKE %..%”进行搜索

于 2013-06-05T14:26:18.030 回答