如何在不使用大型结果集的情况下检查一个字符串是否是另一个字符串的子字符串?
我正在尝试用java编写一个网络价格比较软件。我有一个数据库,其中已经有很多产品类型号(如“ASD01”)。我还有另一个数据库,其产品类型编号如下:“somethingASD01something”。
我想检查数据库#2 是否包含数据库#1 中的字符串。并删除不包含的行。我试图解决这个问题,在结果集中选择两个数据库,并在java代码中比较它们,但它们太大并且使用了太多内存。
我在mysql中找到了LOCATE()方法,它告诉我我想要什么,但我仍然必须使用database#1作为ReultSet,或者还有其他方法来迭代行吗?
I am trying to write a webprice comparison software in java. I have a database which already has a lot of products type number (like 'ASD01'). And I have another database, that has the products type number like this: 'somethingASD01something'.
I want to check if database#2 contains the string in database#1. And delete the rows, where it not contains. I tried to solve it, as selecting both db in a result set, and compare them in the java code, but they are too large and using too much memory.
I found the LOCATE() method in mysql, which tells me what I want, but I still have to use the database#1 as a ReultSet, or are there any other ways to iterate through rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解这个问题,您应该能够使用直接 SQL 删除不需要的记录...
如果您想从 DB2 中删除与 DB1 中的表不匹配的记录,那么 LEFT JOIN 就是一种方法...在字符串比较中使用 DB2 LEFT JOIN DB1,然后删除任何没有 DB1 匹配的 DB2 记录:
If I understand the question correctly, you should be able to delete the records you don't want with straight SQL...
If you want to delete records from DB2 that are NOT matches to a table in DB1, then a LEFT JOIN would be the approach... DB2 LEFT JOIN DB1 on your string comparison, then delete any DB2 record where there isn't a DB1 match: