String query = "SELECT SUM(totalcost) FROM"+m+""; //where totalcost is my column name

    ResultSet rs=st.executeQuery(query);


    while(rs.next())
    {

    System.out.println("SUM(user_id)="+rs.getString(1));

    }


这段代码有什么问题?我的例外是:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:“字段列表”中的未知列“ totalcost”

最佳答案

尝试在from标记后添加一个空格;

String query = "SELECT SUM(totalcost) FROM "+m+"";

09-08 06:50