12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package com.sinosoft.gps.bgd_duty.service;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import com.formaction.Utils;
- import com.persistence.DbConnection;
- @Path("getBGDZiBuMenService")
- public class BGDZiBuMenService {
- @POST
- @ProduceMime("application/json")
- @Path("/getSubDept/")
- public String getSubDept(String params){//修改
- String param = Utils.getParameter("PARENT_ID", params)==null?"":Utils.getParameter("PARENT_ID", params);
- String sql = "select DEPT_ID from SYS_DEPARTMENT where PARENT_ID=?";
- DbConnection dbConn = new DbConnection();//数据库连接
- Connection conn = null;
- PreparedStatement pstm = null;//sql语句的执行者
- ResultSet rs = null;//结果集
- StringBuffer sb = new StringBuffer();
- sb.append("{\"list\":[");
- try {
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- pstm.setString(1, param);
- rs = pstm.executeQuery();
- while(rs.next()){
- sb.append("'" + rs.getString("DEPT_ID") + "',");
- }
- if(sb.length()>9)
- sb.deleteCharAt(sb.length()-1);
- sb.append("]}");
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }finally{
- try {
- if(rs!=null)
- rs.close();
- if(pstm!=null)
- pstm.close();
- if(conn!=null)
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
- }
|