如何使用eclips在java中连接多个表

时间:2015-06-13 05:03:34

标签: java

如果我写这样的代码

$start_nodes = $finder->query('//div[p/@class="start"]');
foreach ($start_nodes as $node) {
    $count = $finder->evaluate('count(preceding-sibling::div[p/@class="start"])', $node)+1;
    echo 'start '. $count .' : <br>';
    $start = 'self::*';
    $end = 'following-sibling::div[p/@class="end"][1]';
    $inbetween = 'following-sibling::div[p/@class="end"][1]/preceding-sibling::*[count(preceding-sibling::div[p/@class="start"])='.$count.']';
    $data_nodes = $finder->query($start.' | '.$inbetween.' | '.$end, $node);
    foreach($data_nodes as $d){
        echo $d->nodeValue .", ";
    }
    echo "<br><br>";
}

它给出了一个错误 'select LID from Login Where Where =“”和Password = 1233456'。

附近的语法不正确

请帮我删除此错误

3 个答案:

答案 0 :(得分:2)

我认为你正在寻找一个subquery。你也可以绑定电子邮件和密码。此外,您应该close Statement(s)。像,

String sql = "insert into Registration(Name,ContactNo,LID) values "
        + "(?,?,(select LID from Login Where Email=? and Password=?))";
PreparedStatement pre1 = null;
try {
    pre1 = cn.prepareStatement(sql);
    // ...
    pre1.setString(3, email);
    pre1.setString(4, pass);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    if (pre1 != null) {
        try {
            pre1.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
}

答案 1 :(得分:0)

我假设一件可能有帮助的事情是将'select LID ...和Password =“+ pass +”'用括号括起来表示这部分的返回值是第三个变量。值函数调用。

答案 2 :(得分:0)

我尝试了以下代码,它在我的系统上运行得非常好,

String query = "insert into test.Registration (Name,ContactNo,LID) values(?,?,(select LID from test.Login where Email='"+email+"' and Password1='"+password+"'))";
PreparedStatement p =con.prepareStatement(query);

您不需要在子查询周围使用单引号,而是将其括在圆括号内。