@Permission("MySQL") contract MySQLExample{ @Description("连接MySQL,参数示例: {\"url\":"39.106.6.6:3306\",\"userName\":\"haiou\",\"pwd\":\"haiou\"}") export function connectDBAndQuery(args){ args = JSON.parse(args); var conn = MySQLUtil.getConnection(args.url,args.userName,args.pwd); if (conn!=undefined && !conn.isClosed()){ print("successfully connected"); } else return "connect failed"; var sql = "select * from haiou.catering limit 0,10"; var statement = conn.createStatement(); var resultSet = statement.executeQuery(sql); ret = []; var meta = resultSet.getMetaData(); for (;resultSet.next();){ var line = { }; for (var j=1;j<=meta.getColumnCount();j++){ line[meta.getColumnName(j)] = resultSet.getString(j); } ret.push(line); } return JSON.stringify(ret); } }