兄弟们帮忙看看以下IF查询代码错在哪里,找了很久不知道,只要有一条件为空就一个都查不到
,只要有一条件为空就一个都查不到,只有第一个IF语句起作用, if ((rcode=="") && (customer_name!="")) 和
if ((rcode!="") && (customer_name=="")) 都不起作用,查出来的是空白。当两个条件都有时才能查出来
package com.ord;
import java.sql.*;
import java.util.*;
import java.io.*;
/**
*ProductBean包含和Product表相关的操作
*/
public class TaBean
{
private Connection con;
private String strs;
//构造方法,获得数据库的连接。
public TaBean()
{
this.con=DataBaseConnection.getConnection();
}
/**
*搜索所有的商品信息。
*返回由Product值对象组成的Collection
*/
public Collection getTaByRcode(String rcode,String customer_name)throws Exception
{
strs="";
Statement stmt=con.createStatement();
if ((rcode!="") && (customer_name!=""))
{
strs="select * from ta1 where rcode='"+rcode+"' and customer_name='"+customer_name+"'";
}
else
if ((rcode=="") && (customer_name!=""))
{
strs="select * from ta1 where customer_name='"+customer_name+"'";
}
else
{
strs="select * from ta1 where rcode='"+rcode+"'";
}
}