a2735050141f0719b52ee2bdd809209dcc7dd801.svn-base 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.sinosoft.gps.bgd_duty.service;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import javax.ws.rs.POST;
  7. import javax.ws.rs.Path;
  8. import javax.ws.rs.ProduceMime;
  9. import com.formaction.Utils;
  10. import com.persistence.DbConnection;
  11. @Path("getBGDZiBuMenService")
  12. public class BGDZiBuMenService {
  13. @POST
  14. @ProduceMime("application/json")
  15. @Path("/getSubDept/")
  16. public String getSubDept(String params){//修改
  17. String param = Utils.getParameter("PARENT_ID", params)==null?"":Utils.getParameter("PARENT_ID", params);
  18. String sql = "select DEPT_ID from SYS_DEPARTMENT where PARENT_ID=?";
  19. DbConnection dbConn = new DbConnection();//数据库连接
  20. Connection conn = null;
  21. PreparedStatement pstm = null;//sql语句的执行者
  22. ResultSet rs = null;//结果集
  23. StringBuffer sb = new StringBuffer();
  24. sb.append("{\"list\":[");
  25. try {
  26. conn = dbConn.getConnection();
  27. pstm = conn.prepareStatement(sql);
  28. pstm.setString(1, param);
  29. rs = pstm.executeQuery();
  30. while(rs.next()){
  31. sb.append("'" + rs.getString("DEPT_ID") + "',");
  32. }
  33. if(sb.length()>9)
  34. sb.deleteCharAt(sb.length()-1);
  35. sb.append("]}");
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. } catch (ClassNotFoundException e) {
  39. e.printStackTrace();
  40. }finally{
  41. try {
  42. if(rs!=null)
  43. rs.close();
  44. if(pstm!=null)
  45. pstm.close();
  46. if(conn!=null)
  47. conn.close();
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. return sb.toString();
  53. }
  54. }