日期:2014-05-18  浏览次数:21003 次

JAVABEAN中写数据库查询语句的问题
环境access+tomcat
11111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
access中查询语句:
***************
select   *   from   products   where   category= 'computer '
或:
select   *   from   products   where   category= "computer "
******************************
javabean中语句:
***************
ResultSet   rst=stmt.executeQuery( "select   *   from   Products   where   category= ' "+categoryId+ " ' ");
22222222222222222222222222222222222222222222222222
22222222222222222222222222222222222222222222222222
access中查询语句:
***************
select   *   from   products   where   name   like   '*1* ';

select   *   from   products   where   name   like   "*1* ";
***************************
javabean中语句:
***************
ResultSet   rst=stmt.executeQuery( "select   *   from   Products   where   name   like   '% "+nameId+ "% '   ");


谁能给我解释下: '% "+nameId+ "% '   这段文字。。。
*******************************************************
具体文件如下:
*********************
public   class   ProductBean
{
private   Connection   con;
//构造方法,获得数据库的连接。
public   ProductBean(){
this.con=DataBaseConnection.getConnection();
}
/按照商品的类别查找商品,
public   Collection   getProductByCategory(String   categoryId)throws   Exception
{
Statement   stmt=con.createStatement();
ResultSet   rst=stmt.executeQuery( "select   *   from   Products   where   category= ' "+categoryId+ " ' ");
Collection   ret=new   ArrayList();
while(rst.next())
{
Product   temp=new   Product();
temp.setProductId(rst.getString( "productid "));
temp.setCategoryId(rst.getString( "category "));
temp.setName(rst.getString( "name "));
temp.setDescription(rst.getString( "descn "));
temp.setProducer(rst.getString( "producer "));
temp.setPrice(rst.getString( "price "));

ret.add(temp);
}
con.close();
return   ret;
}

//按名称匹配查询。
public   Collection   getProductByName(String   nameId)throws   Exception
{
Statement   stmt=con.createStatement();
ResultSet   rst=stmt.executeQuery( "select   *   from   Products   where   name   like   '% "+nameId+ "% '   ");
Collection   ret=new   ArrayList();
while(rst.next())
{
Product   temp=new   Product();
temp.setProductId(rst.getString( "productid "));
temp.setCategoryId(rst.getString( "category "));
temp.setName(rst.getString( "name "));
temp.setDescription(rst.getString( "descn "));
temp.setProducer(rst.getString( "producer "));
temp.setPrice(rst.getString( "price "));

ret.add(temp);
}
con.close();
return   ret;
}
}

*************************************************

------解决方案--------------------
System.out.println( "select * from Products where n