10.28日进度报告
上一次的代码继续
这是后台文件,接下来一下子上代码
package test1; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import com.mysql.jdbc.PreparedStatement; import test1.table; import test1.DBUtil; public class Dao { public static List<table> getTable(String yhf[],String name[],String value[],String jingmo[],int length) { System.out.println(Arrays.toString(yhf)); System.out.println(Arrays.toString(name)); System.out.println(Arrays.toString(value)); System.out.println(Arrays.toString(jingmo)); String sql = "select * from t_table where "; if(yhf[0].equals("binghan")) { if(jingmo[0].equals("jingque")) { sql +=name[0]+" = '"+value[0]+"'"; } else if(jingmo[0].equals("mohu")) { sql = sql + name[0]+" like '%"+value[0]+"%'"; } System.out.println("1:"+sql); } if(yhf[0].equals("buhan")) { if(jingmo[0].equals("jingque")) { sql = sql + "not " + name[0]+" = '"+value[0]+"'"; } else if(jingmo[0].equals("mohu")) { sql = sql + "not " + name[0]+" like '%"+value[0]+"%'"; } System.out.println("2:"+sql); } for(int i=1;i<length;i++) { if(yhf[i].equals("binghan")) { if(jingmo[i].equals("jingque")) { sql = sql + " and "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " and "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("3:"+sql); } else if(yhf[i].equals("huohan")) { if(jingmo[i].equals("jingque")) { sql = sql + " or "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " or "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("4:"+sql); } else if(yhf[i].equals("buhan")) { if(jingmo[i].equals("jingque")) { sql = sql + " not "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " not "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("5:"+sql); } } System.out.println("6:"+sql); List<table> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { table table = new table(); int id = rs.getInt("id"); String jgxqmc = rs.getString("jgxqmc"); String jgmc= rs.getString("jgmc"); String gkglbm = rs.getString("gkglbm"); String szdy = rs.getString("szdy"); String frdb = rs.getString("frdb"); String yzbm = rs.getString("yzbm"); String dwwz = rs.getString("dwwz"); String gjz1 = rs.getString("gjz1"); String dzyx = rs.getString("dzyx"); String qyjg = rs.getString("qyjg"); String xkfl = rs.getString("xkfl"); String yjlx = rs.getString("yjlx"); String hzms = rs.getString("hzms"); String yxdw = rs.getString("yxdw"); table.setId(id); table.setJgxqmc(jgxqmc); table.setJgmc(jgmc); table.setGkglbm(gkglbm); table.setSzdy(szdy); table.setFrdb(frdb); table.setYzbm(yzbm); table.setDwwz(dwwz); table.setGjz(gjz1); table.setDzyx(dzyx); table.setQyjg(qyjg); table.setXkfl(xkfl); table.setYjlx(yjlx); table.setHzms(hzms); table.setYxdw(yxdw); list.add(table); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } //统计查询图表中的value和name值查询 public static List getAllNameValue(String yhf[],String name[],String value[],String jingmo[],int length) { System.out.println(1); String sql = "select jgmc,count(*) from t_table where"; if(yhf[0].equals("binghan")) { if(jingmo[0].equals("jingque")) { sql +=name[0]+" = '"+value[0]+"'"; } else if(jingmo[0].equals("mohu")) { sql = sql + name[0]+" like '%"+value[0]+"%'"; } System.out.println("1:"+sql); } if(yhf[0].equals("buhan")) { if(jingmo[0].equals("jingque")) { sql = sql + "not " + name[0]+" = '"+value[0]+"'"; } else if(jingmo[0].equals("mohu")) { sql = sql + "not " + name[0]+" like '%"+value[0]+"%'"; } System.out.println("2:"+sql); } for(int i=1;i<length;i++) { if(yhf[i].equals("binghan")) { if(jingmo[i].equals("jingque")) { sql = sql + " and "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " and "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("3:"+sql); } else if(yhf[i].equals("huohan")) { if(jingmo[i].equals("jingque")) { sql = sql + " or "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " or "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("4:"+sql); } else if(yhf[i].equals("buhan")) { if(jingmo[i].equals("jingque")) { sql = sql + " not "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " not "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("5:"+sql); } } System.out.println("6:"+sql); List list =new ArrayList(); Connection conn=DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { sql +=" group by jgmc"; System.out.println(sql); state = conn.createStatement(); rs = state.executeQuery(sql); while(rs.next()) { System.out.println(rs.getString(1)); Map<String, Object> map = new HashMap<String, Object>(); map.put("name",rs.getString(1)); map.put("value",rs.getString(2)); list.add(map); } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { return list; }else { return null; } } }
package test1; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * 数据库连接工具 * @author Hu * */ public class DBUtil { public static String db_url = "jdbc:mysql://localhost:3306/doc_system?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8"; public static String db_user = "root"; public static String db_pass = "123456"; public static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver");//加载驱动 conn = DriverManager.getConnection(db_url, db_user, db_pass); } catch (Exception e) { e.printStackTrace(); } return conn; } /** * 关闭连接 * @param state * @param conn */ public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) throws SQLException { Connection conn = getConn(); PreparedStatement pstmt = null; ResultSet rs = null; String sql ="select * from course"; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); if(rs.next()){ System.out.println("空"); }else{ System.out.println("不空"); } } }
package test1; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; public class Duotiaojian { public static List<Service> getAll(String table,String name[],String value[],String flag1[],String flag2[],int n) { List<Service> list=new ArrayList<Service>(); Connection conn=DBUtil.getConn(); PreparedStatement state=null; ResultSet rs=null; //String sql="select * from "+table+" where create_date like'%"+value+"%'"; String sql="select * from "+table+" where"; for(int i=0;i<n;i++) { if(flag1[i].equals("binghan")) { if(flag2[i].equals("jingque")) { sql+=" "+name[i]+" ='"+value[i]+"'"; } else { sql+=" "+name[i]+" like'%"+value[i]+"%'"; } if(i==n-1) { break; } else { sql+=" and"; } } else { if(flag2[i].equals("jingque")) { sql+=" "+name[i]+" ='"+value[i]+"'"; } else { sql+=" "+name[i]+" like'%"+value[i]+"%'"; } if(i==n-1) { break; } else { sql+=" or"; } } } try { state=conn.prepareStatement(sql); rs=state.executeQuery(); while(rs.next()) { System.out.println(rs.getInt(1)); /*Service user=new Service(); user.setId(rs.getInt(1)); user.setUsername(rs.getString(2)); user.setPassword(rs.getString(3)); user.setSalt(rs.getInt(4)); user.setTime(rs.getString(5)); list.add(user);*/ } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { return list; }else { return null; } } }
package test1; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import com.mysql.jdbc.PreparedStatement; import test1.table; import test1.DBUtil; public class SelectDao { public static List<table> getTable(String yhf[],String name[],String value[],String jingmo[],int length) { System.out.println(Arrays.toString(yhf)); System.out.println(Arrays.toString(name)); System.out.println(Arrays.toString(value)); System.out.println(Arrays.toString(jingmo)); String sql = "select * from t_table where "; if(yhf[0].equals("binghan")) { if(jingmo[0].equals("jingque")) { sql +=name[0]+" = '"+value[0]+"'"; } else if(jingmo[0].equals("mohu")) { sql = sql + name[0]+" like '%"+value[0]+"%'"; } System.out.println("1:"+sql); } if(yhf[0].equals("buhan")) { if(jingmo[0].equals("jingque")) { sql = sql + "not " + name[0]+" = '"+value[0]+"'"; } else if(jingmo[0].equals("mohu")) { sql = sql + "not " + name[0]+" like '%"+value[0]+"%'"; } System.out.println("2:"+sql); } for(int i=1;i<length;i++) { if(yhf[i].equals("binghan")) { if(jingmo[i].equals("jingque")) { sql = sql + " and "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " and "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("3:"+sql); } else if(yhf[i].equals("huohan")) { if(jingmo[i].equals("jingque")) { sql = sql + " or "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " or "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("4:"+sql); } else if(yhf[i].equals("buhan")) { if(jingmo[i].equals("jingque")) { sql = sql + " not "+name[i]+" = '"+value[i]+"'"; } else if(jingmo[i].equals("mohu")) { sql = sql + " not "+name[i]+" like '%"+value[i]+"%'"; } else if(jingmo[i].equals("null")) { break; } System.out.println("5:"+sql); } } System.out.println("6:"+sql); List<table> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { table table = new table(); int id = rs.getInt("id"); String jgxqmc = rs.getString("jgxqmc"); String jgmc= rs.getString("jgmc"); String gkglbm = rs.getString("gkglbm"); String szdy = rs.getString("szdy"); String frdb = rs.getString("frdb"); String yzbm = rs.getString("yzbm"); String dwwz = rs.getString("dwwz"); String gjz1 = rs.getString("gjz1"); String dzyx = rs.getString("dzyx"); String qyjg = rs.getString("qyjg"); String xkfl = rs.getString("xkfl"); String yjlx = rs.getString("yjlx"); String hzms = rs.getString("hzms"); String yxdw = rs.getString("yxdw"); table.setId(id); table.setJgxqmc(jgxqmc); table.setJgmc(jgmc); table.setGkglbm(gkglbm); table.setSzdy(szdy); table.setFrdb(frdb); table.setYzbm(yzbm); table.setDwwz(dwwz); table.setGjz(gjz1); table.setDzyx(dzyx); table.setQyjg(qyjg); table.setXkfl(xkfl); table.setYjlx(yjlx); table.setHzms(hzms); table.setYxdw(yxdw); list.add(table); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } //统计查询图表中的value和name值查询 public static List getAllNameValue(String name[],String value[],String flag1[],String flag2[],int n) { System.out.println(1); List list =new ArrayList(); Connection conn=DBUtil.getConn(); Statement state = null; ResultSet rs = null; //String sql="select * from "+table+" where create_date like'%"+value+"%'"; String sql="select jgmc,count(*) from t_table where"; for(int i=0;i<n;i++) { if(flag2[i].equals("jingque")) { sql+=" "+name[i]+" ='"+value[i]+"'"; if(i==n-1) { break; } else { if(flag1[i].equals("binghan")) { sql+=" and "; } else { sql+=" or"; } } } else { sql+=" "+name[i]+" like'%"+value[i]+"%'"; if(i==n-1) { break; } else { if(flag1[i].equals("binghan")) { sql+=" and "; } else { sql+=" or"; } } } } try { sql +=" group by jgmc "; System.out.println(sql); state = conn.createStatement(); rs = state.executeQuery(sql); while(rs.next()) { System.out.print(rs.getString(1)); Map<String, Object> map = new HashMap<String, Object>(); map.put("name",rs.getString(1)); map.put("value",rs.getString(2)); list.add(map); } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { return list; }else { return null; } } }
package test1; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import test1.SelectDao; import test1.table; @WebServlet("/SelectServlet") public class SelectServlet extends HttpServlet { private static final long serialVersionUID = 1L; public SelectServlet() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String[] yhf; yhf=request.getParameterValues("yhf"); String[] name; name=request.getParameterValues("name"); String[] value; value=request.getParameterValues("value"); String[] jingmo; jingmo=request.getParameterValues("jingmo"); List<table> table = SelectDao.getTable(yhf, name, value, jingmo, yhf.length); List list= SelectDao.getAllNameValue(name, value,yhf, jingmo, yhf.length); request.setAttribute("table", table); request.setAttribute("mapDataJson", JSONArray.fromObject(list)); request.getRequestDispatcher("duochange.jsp").forward(request,response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package test1; public class Service { String id; String username; String password; String salt; String create_date; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getSalt() { return salt; } public void setSalt(String salt) { this.salt = salt; } public String getCreate_date() { return create_date; } public void setCreate_date(String create_date) { this.create_date = create_date; } }
package test1; public class table { private String jgmc; private String txdz; private String dwwz; private String dzyx; private String frdb; private String yzbm; private String lxr; private String gddh; private String yddh; private String cz; private String qyjg; private String gkglbm; private String jgjj; private String jgxqmc; private String qsxqnx; private String xkfl; private String xqjsssly; private String jzxqnx; private String szdy; private int status; private String qsxqmx; private String city; private String la; private String sqjsssly; private String datatime; private int result; private String path; private String title; private String owner; private String receiver; public String getJgmc() { return jgmc; } public void setJgmc(String jgmc) { this.jgmc = jgmc; } public String getTxdz() { return txdz; } public void setTxdz(String txdz) { this.txdz = txdz; } public String getDwwz() { return dwwz; } public void setDwwz(String dwwz) { this.dwwz = dwwz; } public String getDzyx() { return dzyx; } public void setDzyx(String dzyx) { this.dzyx = dzyx; } public String getFrdb() { return frdb; } public void setFrdb(String frdb) { this.frdb = frdb; } public String getYzbm() { return yzbm; } public void setYzbm(String yzbm) { this.yzbm = yzbm; } public String getLxr() { return lxr; } public void setLxr(String lxr) { this.lxr = lxr; } public String getGddh() { return gddh; } public void setGddh(String gddh) { this.gddh = gddh; } public String getYddh() { return yddh; } public void setYddh(String yddh) { this.yddh = yddh; } public String getCz() { return cz; } public void setCz(String cz) { this.cz = cz; } public String getQyjg() { return qyjg; } public void setQyjg(String qyjg) { this.qyjg = qyjg; } public String getGkglbm() { return gkglbm; } public void setGkglbm(String gkglbm) { this.gkglbm = gkglbm; } public String getJgjj() { return jgjj; } public void setJgjj(String jgjj) { this.jgjj = jgjj; } public String getJgxqmc() { return jgxqmc; } public void setJgxqmc(String jgxqmc) { this.jgxqmc = jgxqmc; } public String getJzxqmx() { return jzxqmx; } public void setJzxqmx(String jzxqmx) { this.jzxqmx = jzxqmx; } public String getZdkjxqgs() { return zdkjxqgs; } public void setZdkjxqgs(String zdkjxqgs) { this.zdkjxqgs = zdkjxqgs; } public String getGjz() { return gjz; } public void setGjz(String gjz) { this.gjz = gjz; } public String getYjlx() { return yjlx; } public void setYjlx(String yjlx) { this.yjlx = yjlx; } public String getHzms() { return hzms; } public void setHzms(String hzms) { this.hzms = hzms; } public String getYxdw() { return yxdw; } public void setYxdw(String yxdw) { this.yxdw = yxdw; } public String getQsxqnx() { return qsxqnx; } public void setQsxqnx(String qsxqnx) { this.qsxqnx = qsxqnx; } public String getXkfl() { return xkfl; } public void setXkfl(String xkfl) { this.xkfl = xkfl; } public String getXqjsssly() { return xqjsssly; } public void setXqjsssly(String xqjsssly) { this.xqjsssly = xqjsssly; } public String getJzxqnx() { return jzxqnx; } public void setJzxqnx(String jzxqnx) { this.jzxqnx = jzxqnx; } public String getZze() { return zze; } public void setZze(String zze) { this.zze = zze; } public String getZe() { return ze; } public void setZe(String ze) { this.ze = ze; } public String getSzdy() { return szdy; } public void setSzdy(String szdy) { this.szdy = szdy; } public String getQsxqmx() { return qsxqmx; } public void setQsxqmx(String qsxqmx) { this.qsxqmx = qsxqmx; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getLa() { return la; } public void setLa(String la) { this.la = la; } public String getSqjsssly() { return sqjsssly; } public void setSqjsssly(String sqjsssly) { this.sqjsssly = sqjsssly; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public String getDatatime() { return datatime; } public void setDatatime(String datatime) { this.datatime = datatime; } public int getResult() { return result; } public void setResult(int result) { this.result = result; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public String getReceiver() { return receiver; } public void setReceiver(String receiver) { this.receiver = receiver; } public int getId() { return id; } public void setId(int id) { this.id = id; } private String jzxqmx; private String zdkjxqgs; private String gjz; private String yjlx; private String hzms; private String yxdw; private String ze; private String zze; private int id; }