日期:2014-05-16 浏览次数:20444 次
存入数据库
<%
String str1=request.getParameter("str");
String str=java.net.URLDecoder.decode(str1,"utf-8");
java.net.URLDecoder.decode(str,"utf-8");
String instcode=request.getParameter("instcode");
String[] nowRows=str.split(",");
String sql;
String insertsql;
try{?
??? ??? JSONObject obj=new? JSONObject();
??? ??? obj.put("succ1","1"); obj.put("succ2","1");
??? ??? GjjPO po=new GjjPO();
??????? sql=" delete?? from DP147 where INSTCODE = '"+instcode+"'";
??????? int i=po.executeUpdate(sql);
??????? if(i==0)obj.put("succ1","0");
???? if(nowRows.length!=0)
????? {
??????? for(int j=0;j<nowRows.length;j++){
??????? insertsql="insert into? DP147 (INSTCODE,INCLUDEINSTCODE) values ( '"+instcode+"','"+nowRows[j]+"' )";
??????? int m=po.executeUpdate(insertsql);
??????? if(m==0)obj.put("succ2","0");
??????? }
????? }
??????? PersistentTool.commit();
??????? out.println(obj.toString());
}catch(SQLException e1){
??? PersistentTool.rollback();
?? ??? JSONObject obj=new? JSONObject();
?? ??? obj.put("mess",e1.getMessage());
?? ??? out.println(obj.toString());
}
catch(Exception e){
??? PersistentTool.rollback();
?? ??? JSONObject obj=new? JSONObject();
??? obj.put("mess",e.getMessage());
??? out.println(obj.toString());
}
%>
?
?
combobox加载数据
<%
try{??????
??? ??????
??? ?????? String sql ="select INSTCODE,NAME from pb007 ";
??? ?????? GjjPO po=new GjjPO();
?????????? JSONArray jarray=new JSONArray();
??? ??????? BaseBean[] bs=null;
??? ??????? bs=po.query(sql);
??????????? for(int i=0;i<bs.length;i++)
??????????? {??
??????????? ??? JSONObject jo=new JSONObject();
??????????????? String[] names=bs[i].getColNames();
??????????? ??? if(bs[i]!=null){
??????????? ??? ??? for(int j=0;j<names.length;j++){
??????????? ??? ??? ??? jo.put(names[j],bs[i].get(j).toString().trim());
??????????? ??? ??? }
??????????? ??? }
??????????? ??? jarray.put(jo);
??????????? }
???????????? out.print(jarray.toString());
}catch(SQLException e1){
??? PersistentTool.rollback();
?? ??? JSONObject obj=new? JSONObject();
?? ??? obj.put("mess",e1.getMessage());
?? ??? out.println(obj.toString());
}
catch(Exception e){
??? PersistentTool.rollback();
?? ??? JSONObject obj=new? JSONObject();
??? obj.put("mess",e.getMessage());
??? out.println(obj.toString());
}
?
%>