Sql语句Java表示2个表和2个值(变量)

时间:2013-04-17 18:37:44

标签: java mysql sql select jdbc

我正在尝试执行以下操作并且它不接受它。

String sql_eco = "select * from orders where EmployeeID=" +e_ID + " and CustomerID ="' + cu_ID + "'";

从两个表和两个值(变量)中选择

4 个答案:

答案 0 :(得分:0)

尝试,假设CustomerIDEmployeeID都是Integer列类型

String sql_eco = "select * from orders where EmployeeID=" +e_ID + " and CustomerID =" + cu_ID;

答案 1 :(得分:0)

试试这个:

String sql_eco = "select * +
                  from orders +
                  where EmployeeID=" +e_ID + " and CustomerID ='" + cu_ID + "'";   
                                                               ^                                                                         

答案 2 :(得分:0)

使用它。你错放了“for CustomerId

String sql_eco = "select * from orders where EmployeeID=" +e_ID + " and CustomerID ='" + cu_ID + "'";

答案 3 :(得分:0)

值变量你想说这样的话吗?

String sql_eco = "select * +
                  from orders +
                  where 1=1 ";
if(e_ID  != null) {
 sql_eco += " AND EmployeeID=" +e_ID ;
}
if(cu_ID  != null){
 sql_eco  += " and CustomerID ='" + cu_ID + "'";  
}

要改进此代码,您可以使用stringbuilder/stringbuffer

相关问题