67,513
社区成员
发帖
与我相关
我的任务
分享
public class test extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("Hello Servlet");
PrintWriter out = resp.getWriter();
out.println(getData());
out.flush();
out.close();
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("Hello Servlet POST");
}
public String getData() {
try {
DBUtil DB = new DBUtil("localhost", "3306", "testDemo", "root", "123456");
DB.connect2DB();
List<Map<String, Object>> data = DB.selectSQL("Select * from Student");
JSONArray _json = JSONArray.fromObject(data);
return _json.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
DBUtil DB = new DBUtil("www.flyingspace.cn", "3306", "test", "lc", "123456");
DB.connect2DB();
List<Map<String, Object>> data = DB.selectSQL("Select * from Student");
JSONArray _json = JSONArray.fromObject(data);
System.out.println(_json);
}
}