String attribute = "age";
String attributesplit= "youth";
  
Query("select age from cusinfo where class = 'yes' and age = 'youth'");  得出的结果是正确的。可下面的语句 运行报错 说 Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'selectagefrom cusinfo where class = 'yes' and age= 'youth'' at "。   Query("select"  + attribute +  "from cusinfo where class = 'yes' and " + attribute + "= '"+ attributesplit +"'");
不知道问题出在哪?有知道的请帮忙解决一下。

解决方案 »

  1.   

    空格啊。
    比如"select"  + attribute 结果是selectage 谁也不认得这是什么了。
      

  2.   

     Query("select "  + attribute +  " from cusinfo where class = 'yes' and  " + attribute + "= ' "+ attributesplit +"'"); LZ注意看看空格的位置,你加错位置了
      

  3.   


    呵呵,给你个建议,把生成的sql打出来看看就知道了,呵呵
      

  4.   

    呵呵,刚看SQL不久,但也知道是没写空格造成的。
    同情,我也经常粗心……
      

  5.   

    Query("select"  + attribute +  "from cusinfo where class = 'yes' and " + attribute + "= '"+ attributesplit +"'"); 这个看着就有点晕,有简单的方法最好用简单的吧。
    到了没有办法的地步才仔细研究。