我正在开发一个应用程序,我需要将一些数据从服务器数据库复制到 android 中的本地 SQLite 数据库表。该表包含超过 1000 条记录。首先,我为此编写了 servlet 代码。我使用三个数组(村名、村号和区号)。我的代码是
public class vlgmas extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet vlgmas</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet vlgmas at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Pickvalue</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Pick at " + request.getContextPath () + "</h1>");
doPost(request,response);
out.println("</body>");
out.println("</html>");
} finally
{
out.close();
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//processRequest(request, response);
String vname = null,vcode=null,divsec=null;
JSONObject obj = new JSONObject();
List list = new ArrayList();
JSONObject obj2 = new JSONObject();
PrintWriter out = response.getWriter();
String vn[]=new String[2000],vc[]=new String[2000],ds[]=new String[2000];
int t,r1=0,r2=0,r3=0;
try
{
// JSONObject obj1=new JSONObject();
Class.forName("oracle.jdbc.driver.OracleDriver");
java.sql.Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.200:1521:pdsm", "test", "test");
Statement stmt=conn.createStatement();
{
ResultSet rs = stmt.executeQuery("select * from cn_vlgmas");
while(rs.next())
{
vn[r1++]=rs.getString ("vlgname");
vc[r2++]=rs.getString("vlgcode");
ds[r3++]=rs.getString("divsec");
}
for(t=0;t<r1;t++)
{
out.println(vn[t]+","+vc[t]+","+ds[t]);
}
/*obj.put("vname",vname);
obj.put("vcode", vcode);
obj.put("divsec", divsec);
list.add(obj);
obj2.accumulate("get", list);
out.println(obj2);*/
}
}catch(Exception e)
{
out.println("error"+e.toString());
}
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
它显示了我预期的所有细节。但我不知道如何在我的 android 代码中分别检索这三个数组。我需要为 1000 条记录中的每一条检索每个村庄名称、村庄代码和分区代码。任何人都可以帮助我做到这一点。
提前致谢