简体   繁体   English

我如何从MySQL到Java(jdbc)使用@

[英]How can i use @ from mysql to java(jdbc)

I can use @ in mysql. 我可以在mysql中使用@。 But I can't use @ in java(jdbc). 但是我不能在java(jdbc)中使用@。 Could you give some advice? 你能给点建议吗?

mysql (working very well) mysql(工作得很好)

select ssn from (select * from EMPLOYEE)EMPLOYEE_sorted,(select 
@pv='888665555') initialisation where find_in_set(superssn,@pv) and length(@pv 
:= concat(@pv,',',ssn));

java (jdbc) doesn't work java(jdbc)不起作用

String query = "select ssn from (select * from EMPLOYEE)EMPLOYEE_sorted, 
(select @pv=888665555) initialisation where find_in_set(superssn,@pv) and length(@pv := concat(@pv,',',ssn))"

To set this you may create a PreparedStatement and assign '?' 要进行设置,您可以创建一个PreparedStatement并分配“?” wherever you want to place the @xxxxxx. 无论您要将@xxxxxx放在哪里。

To set the values inside the '?' 在“?”内设置值 you have to use the command 你必须使用命令

setString()/setInt()/set<variable>();

This is more clear when I show you an example. 当我给您看一个例子时,这一点更加清楚。

PreparedStatement p = con.prepareStatement("select * from people where 
(first_name = ? or last_name = ?) and address = ?");
p.setString(1, name);
p.setString(2, name);
p.setString(3, address);

Here is the link to the sample. 这是示例的链接

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

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