//package com.ynxbd.wx.utils; // //import com.ynxbd.wx.config.datasource.DataBase; //import org.apache.commons.beanutils.BeanUtils; //import org.codehaus.jackson.map.ObjectMapper; // //import javax.servlet.ServletRequest; //import javax.servlet.http.HttpServletResponse; //import java.io.IOException; //import java.io.PrintWriter; //import java.io.UnsupportedEncodingException; //import java.lang.reflect.InvocationTargetException; //import java.nio.charset.StandardCharsets; //import java.sql.*; //import java.util.*; // // //public class ObjMake { // // public ObjMake() { // // } // // public static Vector> popRs(int string, ResultSet rs) { // Vector> vector = new Vector<>(); // try { // Map map; // Object value; // String fdname; // ResultSetMetaData rmd = rs.getMetaData(); // int ColumnCount = rmd.getColumnCount(); // while (rs.next()) { // map = new HashMap<>(); // for (int i = 1; i <= ColumnCount; i++) { // if (string == 0) // value = rs.getObject(i); // else // value = rs.getString(i); // fdname = rmd.getColumnLabel(i).toLowerCase(); // map.put(fdname, value); // } // vector.add(map); // } // } catch (SQLException ex) { // ex.printStackTrace(); // } // return vector; // } // // /** // * @param obj - bean���� // * @param rs - ��Ҫ�󶨵���ݼ� // * @return Vector // */ // public static Vector> popRs(Object obj, ResultSet rs) { // Map map = new HashMap<>(); // Vector> vector = new Vector<>(); // Object value = null; // Object bean = null; // // if (obj != null) { // Class clazz = obj.getClass(); // try { // ResultSetMetaData rmd = rs.getMetaData(); // while (rs.next()) { // try { // bean = clazz.newInstance(); // } catch (IllegalAccessException | InstantiationException ex1) { // ex1.printStackTrace(); // } // // for (int i = 1; i <= rmd.getColumnCount(); i++) { // String fdname = rmd.getColumnLabel(i).toLowerCase(); // // System.out.println(fdname); // String fdtype = rmd.getColumnTypeName(i); // if (fdtype.indexOf("(") > 0) // fdtype = fdtype.substring(0, fdtype.indexOf("(")); // if (fdtype.toUpperCase().contains("CHAR") || fdtype.toUpperCase().equals("LONG") || "DECIMAL".equals(fdtype)) // // value = iso2gb(rs.getString(fdname)); // // //�ַ�仯windows // value = rs.getString(fdname); // �ַ�仯linux // else if (fdtype.equals("DATE") || fdtype.equals("DATETIME")) { // try { // value = rs.getTimestamp(fdname); // String s = value.toString(); // if (s.indexOf(".0") > 0) { // value = s.substring(0, s.indexOf(".0")); // } // } catch (Exception e) { // e.printStackTrace(); // } // } else if (fdtype.equals("NUMBER") || fdtype.equals("DOUBLE")) { // if (rmd.getScale(i) == 0) // value = rs.getInt(fdname); // else // value = String.valueOf(rs.getDouble(fdname)); // } else if (fdtype.toUpperCase().contains("INT")) { // if ("BIGINT".equals(fdtype.toUpperCase())) { // value = rs.getLong(fdname); // } else { // value = rs.getInt(fdname); // } // } else if (fdtype.equals("FLOAT")) { // value = String.valueOf(rs.getFloat(fdname)); // } // // if (value != null) // map.put(fdname, value); // value = null; // } // try { // // BeanUtils.populate(bean, map); // vector.add(map); // map.clear(); // } catch (InvocationTargetException | IllegalAccessException ex) { // ex.printStackTrace(); // } // } // } catch (SQLException ex) { // ex.printStackTrace(); // } // // } else { // try { // ResultSetMetaData rmd = rs.getMetaData(); // while (rs.next()) { // map = new HashMap<>(); // for (int i = 1; i <= rmd.getColumnCount(); i++) { // String fdname = rmd.getColumnLabel(i).toLowerCase(); // // System.out.println(fdname); // String fdtype = rmd.getColumnTypeName(i); // if (fdtype.indexOf("(") > 0) // fdtype = fdtype.substring(0, fdtype.indexOf("(")); // if (fdtype.toUpperCase().contains("CHAR") || fdtype.toUpperCase().equals("LONG")) // // value = iso2gb(rs.getString(fdname)); // // //�ַ�仯windows // value = rs.getString(fdname); // �ַ�仯linux // else if (fdtype.equals("DATE") || fdtype.equals("DATETIME")) { // try { // value = rs.getTimestamp(fdname); // String s = value.toString(); // if (s.indexOf(".0") > 0) { // value = s.substring(0, s.indexOf(".0")); // } // } catch (Exception e) { // e.printStackTrace(); // } // } else if (fdtype.equals("NUMBER") || fdtype.equals("DOUBLE")) { // if (rmd.getScale(i) == 0) // value = rs.getInt(fdname); // else // value = String.valueOf(rs.getDouble(fdname)); // } else if (fdtype.toUpperCase().contains("INT")) { // if ("BIGINT".equals(fdtype.toUpperCase())) { // value = rs.getLong(fdname); // } else { // value = rs.getInt(fdname); // } // // } else if (fdtype.equals("FLOAT")) { // value = String.valueOf(rs.getFloat(fdname)); // } // // if (value != null) // // System.out.println(fdname + " : " +value); // map.put(fdname, value); // value = null; // } // // vector.add(map); // // } // } catch (SQLException ex) { // ex.printStackTrace(); // } // } // // return vector; // } // // /** // * ��ý���е������Լ��е���ƺ����� // * // * @param obj - // * ��Ҫ����ݵ�bean // * @param rs - // * ��ݼ� // */ // public static void popRsSingle(Object obj, ResultSet rs) { // Map map = new HashMap<>(); // Object value = null; // try { // // ResultSetMetaData rmd = rs.getMetaData();// ������� // for (int i = 1; i <= rmd.getColumnCount(); i++) { // String fdName = rmd.getColumnName(i).toLowerCase();// ���ָ���е����ת��ΪСд // String fdType = rmd.getColumnTypeName(i);// ���ָ���е�������� // if (fdType.indexOf("(") > 0) // fdType = fdType.substring(0, fdType.indexOf("(")); // // if (fdType.toUpperCase().contains("CHAR")) // ���е��������ת���ɴ�д // // ���Ƿ���CHAR��ͬ // // value = iso2gb(rs.getString(fdname)); //�ַ�仯windows // value = rs.getString(fdName); // �ַ�仯linux // else if (fdType.equals("DATE") || fdType.equals("DATETIME")) {// ���ڸ�ʽ // try { // value = rs.getTimestamp(fdName).toString(); // // String s = value.toString(); // if (s.indexOf(".0") > 0) { // value = s.substring(0, s.indexOf(".0")); // } // } catch (Exception e) { // e.printStackTrace(); // } // } else if (fdType.equals("NUMBER") || fdType.equals("DOUBLE")) { // if (rmd.getScale(i) == 0) // ��ָ�����е�����������С����Ȩ�� // value = rs.getInt(fdName); // else // value = String.valueOf(rs.getDouble(fdName));// Double->����->String // } else if (fdType.toUpperCase().contains("INT")) { // value = rs.getInt(fdName); // } // // if (value != null) { // map.put(fdName, value); // } // value = null; // } // BeanUtils.populate(obj, map); // // } catch (Exception e) { // e.printStackTrace(); // } // } // // /** // * ��������ݰ󶨵�bean�� // * // * @param obj - // * ����ݵ�bean // * @param request - // * ������� // */ // public static void pop(Object obj, ServletRequest request) { // // Map map = new HashMap<>(); // String name; // String value; // // Enumeration parameterNames = request.getParameterNames(); // while (parameterNames.hasMoreElements()) { // name = parameterNames.nextElement(); // value = request.getParameter(name); // // if (value != null) { // map.put(name, value); // } // } // // try { // BeanUtils.populate(obj, map); // // } catch (InvocationTargetException | IllegalAccessException ex) { // ex.printStackTrace(); // } // } // // /** // * ��map�е���ݰ󶨵�bean�� // * // * @param obj Object ���bean // * @param map HashMap ��� // */ // public static void pop(Object obj, HashMap map) { // try { // BeanUtils.populate(obj, map); // } catch (InvocationTargetException | IllegalAccessException ex) { // ex.printStackTrace(); // } // } // // /** // * @param s // * @return String // */ // public static String message(String s) { // String returnVal = ""; // returnVal = returnVal + ""; // returnVal = returnVal + "Servlet1"; // returnVal = returnVal + ""; // returnVal = returnVal + ""; // returnVal = returnVal + ""; // return returnVal; // } // // /** // * @param response // * @param s // */ // public static void sendMessage(HttpServletResponse response, String s) { // response.setContentType("text/html; charset=UTF-8"); // try { // PrintWriter out = response.getWriter(); // out.println(message("alert(\"" + s + "\");")); // } catch (IOException ex) { // ex.printStackTrace(); // } // } // // public static java.sql.Date getCurrentDate() { // java.util.Date d = new java.util.Date(); // return new java.sql.Date(d.getYear(), d.getMonth(), d.getDate()); // } // // public static java.sql.Date getCurrentDateTime() { // java.util.Date d = new java.util.Date(); // return new java.sql.Date(d.getTime()); // } // // /** // * ��ݵõ���id������Ӧ�Ķ��� // * // * @param clsName // * @param request // * @return // */ // public static Object pop(String clsName, ServletRequest request) { // try { // Class cls = Class.forName(clsName); // Object o = cls.newInstance(); // pop(o, request); // return o; // } catch (Exception e) { // e.printStackTrace(); // } // return null; // } // // public static Vector> popRs(String clsName, ResultSet rs) { // try { // if ("Object".equals(clsName)) { // return popRs("0", rs); // } else if ("String".equals(clsName)) { // return popRs("1", rs); // } else { // Object o = null; // if (clsName != null) { // Class cls = Class.forName(clsName); // o = cls.newInstance(); // } // return popRs(o, rs); // } // } catch (Exception e) { // e.printStackTrace(); // } // return new Vector<>(); // } // // /** // * @param clsName // * @param rs // * @return // */ // public static Object popRsSingle(String clsName, ResultSet rs) { // try { // Object o = Class.forName(clsName).newInstance(); // popRsSingle(o, rs); // return o; // } catch (Exception e) { // e.printStackTrace(); // } // return null; // } // // public static Vector> popRsBySql(String sql, String clsName, Connection con) { // try { // if (con.isClosed()) { // con = DataBase.getConnection(); // } // Statement stmt = con.createStatement(); // ResultSet rs = stmt.executeQuery(sql); // // Vector> v = popRs(clsName, rs); // rs.close(); // stmt.close(); // // return v; // } catch (SQLException e) { // e.printStackTrace(); // } finally { // DataBase.close(con); // } // return new Vector<>(); // } // // public static String JsonRsBySql(String sql, Connection con) { // try { // if (con.isClosed()) { // con = DataBase.getConnection(); // } // Statement stmt = con.createStatement(); // ResultSet rs = stmt.executeQuery(sql); // List> list = popRs(null, rs); // rs.close(); // stmt.close(); // ObjectMapper mapper = new ObjectMapper(); // // return mapper.writeValueAsString(convertSelect2(list)); // } catch (IOException | SQLException e) { // e.printStackTrace(); // } finally { // DataBase.close(con); // } // return "[]"; // } // // public static List convertSelect2(List> rs) { // List l = new ArrayList<>(); // // Object content; // Object id; // Map m; // int i = 0; // for (Map map : rs) { // m = new HashMap<>(); // content = map.get("content"); // id = map.get("id"); // if (content == null) { // m.put("text", ""); // } else { // m.put("text", content.toString()); // } // if (id == null) { // m.put("id", String.valueOf(i)); // } else { // m.put("id", id.toString()); // } // // i++; // l.add(m); // } // return l; // } // // public static Vector> popRsBySql_old(String sql, String clsName, Connection con) { // try { // if (con.isClosed()) { // con = DataBase.getConnection(); // } // Statement stmt = con.createStatement(); // ResultSet rs = stmt.executeQuery(sql); // // Vector> v = popRs(clsName, rs); // rs.close(); // stmt.close(); // // return v; // } catch (SQLException e) { // System.out.println(e.getMessage()); // } // return new Vector<>(); // } // // public static String executeSql1(String strSql, Connection con) throws SQLException { // // con.setAutoCommit(false); // Statement m_statement = con.createStatement(); // String state = ""; // state = String.valueOf(m_statement.executeUpdate(strSql)); // con.commit(); // m_statement.close(); // con.setAutoCommit(true); // return state; // // } // // public static String executeSql(String strSql, Connection con) { // try { // if (con.isClosed()) { // con = DataBase.getConnection(); // } // con.setAutoCommit(false); // Statement m_statement = con.createStatement(); // String state = ""; // // System.out.print(strSql); // state = String.valueOf(m_statement.executeUpdate(strSql)); // con.commit(); // m_statement.close(); // con.setAutoCommit(true); // // return state; // } catch (SQLException e) { // try { // con.rollback(); // } catch (SQLException ex) { // return e.toString() + "\t" + ex.toString(); // } // return e.toString(); // } finally { // DataBase.close(con); // } // } // // // public static String executeSql_old(String strSql, Connection con) { // try { // if (con.isClosed()) { // con = DataBase.getConnection(); // } // con.setAutoCommit(false); // Statement m_statement = con.createStatement(); // String state = ""; // state = String.valueOf(m_statement.executeUpdate(strSql)); // con.commit(); // m_statement.close(); // con.setAutoCommit(true); // // return state; // } catch (SQLException e) { // try { // con.rollback(); // // } catch (SQLException ex) { // return e.toString() + "\t" + ex.toString(); // } // return e.toString(); // } // } // // /** // * ����������⣬ISOתΪUTF-8���룬����POST��GET��ʽȡ����� // * // * @param str ԭʼ�ı� // * @return ת�����ı� // */ // public static String iso2gb(String str) { // if (str != null) { // byte[] tem = null; // try { // tem = str.getBytes("ISO8859_1"); // } catch (UnsupportedEncodingException e) { // System.out.println("Error: Method: dbconn.iso2gb :" + e.getMessage()); // } // if (tem != null) { // str = new String(tem, StandardCharsets.UTF_8); // } // } // return str; // } // // // ===================================================================== // // /** // * ����������⣬UTF-8תISO���룬���ڴ���ݿ��д���ת�� // * // * @param str ԭʼ�ı� // * @return ת�����ı� // */ // public static String gb2iso(String str) { // if (str != null) { // byte[] tep = null; // tep = str.getBytes(StandardCharsets.UTF_8); // try { // str = new String(tep, "ISO8859_1"); // } catch (UnsupportedEncodingException e) { // System.out.println("Error: Method: dbconn.gb2iso :" + e.getMessage()); // } // } // return str; // } // //}