我有以下代码,
function report1() {
var conn = Jdbc.getConnection(url, name,passward);
var sql = conn.prepareStatement("SET @sql = NULL; ");
var group_concat_max_len = conn.prepareStatement("SET @@group_concat_max_len = 40000; ");
var sel_querry = conn.prepareStatement("SELECT GROUP_CONCAT(DISTINCT \
CONCAT(' IFNULL(COUNT(case when pt.name = ', '\'', name, '\'',' THEN 1 END),0) AS ', replace(name, ' ', '_')) \
) INTO @sql \
from propertytypes; ");
var set_querry = conn.prepareStatement(" SET @sql = CONCAT('SELECT c.name as city,date(pr.created_at) as date,' \
,@sql, \
', IFNULL(COUNT(pr.id),0) AS Total \
from properties pr \
LEFT JOIN cities c on c.id = pr.city_id \
LEFT JOIN propertytypes pt on pt.id = pr.propertytype_id where pr.status = \'Active\' \
group by city, date(pr.created_at) \
ORDER BY date,Total DESC');");
var stmt = conn.prepareStatement(" PREPARE stmt FROM @sql; ");
var execute = conn.prepareStatement(" EXECUTE stmt; ");
var deallocate =conn.prepareStatement( " DEALLOCATE PREPARE stmt; ");
sql.executeQuery();
group_concat_max_len.executeQuery();
sel_querry.executeQuery();
set_querry.executeQuery();
stmt.executeQuery();
execute.executeQuery();
deallocate.executeQuery();
var mat1 = [];
mat1[0] = [];
for (j=0; j<result1.getMetaData().getColumnCount(); j++){
mat1[0].push(result1.getMetaData().getColumnName(j+1));
}
var row = 0;
while(result1.next()) {
mat1[row+1] = [];
for(var i=0; i<1; i++) { // four fields per record
mat1[row+1][i] = result1.getString(i+1);
}
for(var i=1; i<result1.getMetaData().getColumnCount(); i++) { // four fields per record
mat1[row+1][i] = result1.getInt(i+1);
}
row++;
}
return mat1;
}
但是我得到一个错误:“你的SQL语法有错误;请查看与你的MySQL服务器版本相对应的手册,以获得正确的语法,使用靠近''group by city,date(pr.created_at)ORDER BY '在第1行(第74行,文件“asd”)“。在set_querry.executeQuery();
但是mysql代码在workbench中工作。任何人都可以找出问题。?