设唯一标识用户的是id
String jsonString = "{";
preparedStatement = connection.prepareStatement("select name,url,page from table_a where id = 1 limit 1");
ResultSet rs = preparedStatement.executeQuery();
rs.first();
String name = rs.getString(1);
String url = rs.getString(2);
String page = rs.getInt(3);
jsonString += "'name':'" +name+ "',";
jsonString += "'url':'" + url + "',";
jsonString += "'page':" + page + ",";
jsonString += "'links':[";
rs = preparedStatement.executeQuery("select name,url from table_b where frid=1");
while(rs.next()){
jsonString+="{'name':'"+rs.name+"',";
jsonString+="'url':'"+rs.url+"'},";
}
jsonString = jsonString.substring(0,jsonString.length()-1);
jsonString += "]}";
rs.mustclose();
preparedStatement.mustclose();
connection.mustclose();
writer.write(jsonString);
writer.mustclose();
在安卓端请求该servlet后返回的jsonString用JSONObject 或其他工具类转化为json对象用