我知道这可能是一个有点奇怪的问题,但基本上就是这样:
public static void main(String[] args) throws IOException //Alternatively, you should probably handle this.
{
//I don't know what your source is for the search strings,
//but this will simulate them.
String[] toSearch = {"Strings", "to", "search", "for."};
//Simplest way to read a file when no editing is needed.
for (String line : Files.readAllLines(FileSystems.getDefault().getPath("input.txt")))
{
for (String str : toSearch)
{
//Simplest way to check if one String contains another.
if (line.contains(str))
{
System.out.println("Yup!");
//Now that we know the file contains a String, no need to continue.
return;
}
}
}
//If it even gets to this point, it got through the file with no match.
System.out.println("Fail!");
}
我想更问题的问题是,在回滚/提交时是否必须存在$pdo->beginTransaction();
$stmt = $pdo->prepare('...');
$stmt->bindValue(':something', $something);
if (!$stmt->execute()) { $pdo->rollBack(); }
$stmt = null;
$stmt = $pdo->prepare('...');
$stmt->bindValue(':something', $something);
if (!$stmt->execute()) { $pdo->rollBack(); }
$stmt = null;
$pdo->commit();
,还是纯粹在数据库级别执行回滚,这并不重要。
对此的一些随机失败可归因于$stmt
清除gc
之前的语句吗?此外,如果没有后一次回滚,情况是否会发生变化 - 即如果第二次声明失败不构成rollBack?
注意!我希望在较低的层面上理解这个过程。我完全清楚这些语句可以在单独的变量中,并在事务提交后清理。 :)