- 浏览: 50964 次
- 性别:
- 来自: 台源
-
最新评论
此文为转载,权作参考!
package com.jasson.im.api; import java.io.UnsupportedEncodingException; import java.sql.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; // Referenced classes of package com.jasson.im.api: // MOItem, RPTItem public class APIClient { public static final int IMAPI_SUCC = 0; public static final int IMAPI_CONN_ERR = -1; public static final int IMAPI_CONN_CLOSE_ERR = -2; public static final int IMAPI_INS_ERR = -3; public static final int IMAPI_DEL_ERR = -4; public static final int IMAPI_QUERY_ERR = -5; public static final int IMAPI_DATA_ERR = -6; public static final int IMAPI_API_ERR = -7; public static final int IMAPI_DATA_TOOLONG = -8; public static final int IMAPI_INIT_ERR = -9; public static final int IMAPI_IFSTATUS_INVALID = -10; public static final int IMAPI_GATEWAY_CONN_ERR = -11; private String dbUser; private String dbPwd; private String apiCode_; private String dbUrl; private Connection conn; public APIClient() { dbUser = null; dbPwd = null; apiCode_ = null; dbUrl = null; conn = null; } public int init(String dbIP, String dbUser, String dbPwd, String apiCode) { release(); this.dbUser = dbUser; this.dbPwd = dbPwd; apiCode_ = apiCode; dbUrl = "jdbc:mysql://" + dbIP + "/im"; return testConnect(); } public int init(String dbIP, String dbUser, String dbPwd, String apiCode, String dbName) { release(); this.dbUser = dbUser; this.dbPwd = dbPwd; apiCode_ = apiCode; dbUrl = "jdbc:mysql://" + dbIP + "/" + dbName; return testConnect(); } public int sendSM(String mobile, String content, long smID) { return sendSM(new String[] { mobile }, content, smID, smID); } public int sendSM(String mobiles[], String content, long smID) { return sendSM(mobiles, content, smID, smID); } public int sendSM(String mobiles[], String content, long smID, long srcID) { return sendSM(mobiles, content, smID, srcID, ""); } public int sendSM(String mobiles[], String content, String sendTime, long smID, long srcID) { return sendSM(mobiles, content, smID, srcID, "", sendTime); } public int sendSM(String mobile, String content, long smID, String url) { return sendSM(new String[] { mobile }, content, smID, url); } public int sendSM(String mobiles[], String content, long smID, String url) { return sendSM(mobiles, content, smID, smID, url); } public int sendSM(String mobiles[], String content, long smID, long srcID, String url) { return sendSM(mobiles, content, smID, smID, url, ""); } public int sendSM(String mobiles[], String content, long smID, long srcID, String url, String sendTime) { if(dbUrl == null) { return -9; } if(mobiles == null || mobiles.length == 0) { return -6; } StringBuffer mobileBuf = new StringBuffer(); for(int i = 0; i < mobiles.length; i++) { mobileBuf.append(",").append(mobiles[i]); } if(mobileBuf.length() > 1) { mobileBuf.delete(0, 1); } else { return -6; } String contenttmp = replaceSpecilAlhpa(content); if(contenttmp.length() < 1) { return -6; } if(contenttmp.length() > 2000) { contenttmp = contenttmp.substring(0, 2000); } if(!checkSmID(smID) || !checkSmID(srcID)) { return -6; } if(url != null && url.length() > 0) { if(url.length() > 110) { return -8; } if((url + contenttmp).length() > 120) { return -8; } } int ret = checkGatConn(); if(ret != 1) { return ret; } if(!"".equals(sendTime) && isDateTime(sendTime) == null) { return -6; } else { return mTInsert(mobileBuf.toString(), contenttmp, smID, srcID, url, sendTime); } } public MOItem[] receiveSM() { Statement st; String getMoSql; String delMoSql; ArrayList moList; StringBuffer snBuf; if(dbUrl == null) { return null; } if(conn == null) { int state = initConnect(); if(state != 0) { return null; } } st = null; ResultSet rs = null; getMoSql = "select * from api_mo_" + apiCode_ + " limit 5000"; delMoSql = "delete from api_mo_" + apiCode_ + " where AUTO_SN in ("; moList = new ArrayList(); snBuf = new StringBuffer("-1"); st = conn.createStatement(); ResultSet rs; MOItem mItemtmp; for(rs = st.executeQuery(getMoSql); rs.next(); moList.add(mItemtmp)) { mItemtmp = new MOItem(); mItemtmp.setSmID(rs.getLong("SM_ID")); mItemtmp.setContent(rs.getString("CONTENT")); mItemtmp.setMobile(rs.getString("MOBILE")); mItemtmp.setMoTime(rs.getString("MO_TIME")); snBuf.append(",").append(rs.getString("AUTO_SN")); } rs.close(); st.executeUpdate(delMoSql + snBuf.toString() + ")"); break MISSING_BLOCK_LABEL_291; Exception e; e; MOItem amoitem[]; releaseConn(); amoitem = null; closeStatment(st); return amoitem; Exception exception; exception; closeStatment(st); throw exception; closeStatment(st); MOItem moItem[] = new MOItem[0]; return (MOItem[])moList.toArray(moItem); } public MOItem[] receiveSM(long srcID, int amount) { Statement st; String getMoSql; String delMoSql; ArrayList moList; StringBuffer snBuf; if(dbUrl == null) { return null; } if(conn == null) { int state = initConnect(); if(state != 0) { return null; } } st = null; ResultSet rs = null; getMoSql = "select * from api_mo_" + apiCode_; if(srcID != -1L) { getMoSql = getMoSql + " where SM_ID=" + srcID; } if(amount != -1) { getMoSql = getMoSql + " limit " + amount; } delMoSql = "delete from api_mo_" + apiCode_ + " where AUTO_SN in ("; moList = new ArrayList(); snBuf = new StringBuffer("-1"); st = conn.createStatement(); ResultSet rs; MOItem mItemtmp; for(rs = st.executeQuery(getMoSql); rs.next(); moList.add(mItemtmp)) { mItemtmp = new MOItem(); mItemtmp.setSmID(rs.getLong("SM_ID")); mItemtmp.setContent(rs.getString("CONTENT")); mItemtmp.setMobile(rs.getString("MOBILE")); mItemtmp.setMoTime(rs.getString("MO_TIME")); snBuf.append(",").append(rs.getString("AUTO_SN")); } rs.close(); st.executeUpdate(delMoSql + snBuf.toString() + ")"); break MISSING_BLOCK_LABEL_372; Exception e; e; MOItem amoitem[]; releaseConn(); amoitem = null; closeStatment(st); return amoitem; Exception exception; exception; closeStatment(st); throw exception; closeStatment(st); MOItem moItem[] = new MOItem[0]; return (MOItem[])moList.toArray(moItem); } public RPTItem[] receiveRPT() { Statement st; String getRPTSql; String delRPTSql; ArrayList rptList; StringBuffer snBuf; if(dbUrl == null) { return null; } ResultSet rs = null; st = null; if(conn == null) { int state = initConnect(); if(state != 0) { return null; } } getRPTSql = "select * from api_rpt_" + apiCode_ + " limit 5000"; delRPTSql = "delete from api_rpt_" + apiCode_ + " where AUTO_SN in ("; RPTItem rptItem[] = (RPTItem[])null; rptList = new ArrayList(); snBuf = new StringBuffer("-1"); st = conn.createStatement(); ResultSet rs; RPTItem rptItemtmp; for(rs = st.executeQuery(getRPTSql); rs.next(); rptList.add(rptItemtmp)) { rptItemtmp = new RPTItem(); rptItemtmp.setSmID(rs.getLong("SM_ID")); rptItemtmp.setCode(rs.getInt("RPT_CODE")); rptItemtmp.setMobile(rs.getString("MOBILE")); rptItemtmp.setDesc(rs.getString("RPT_DESC")); rptItemtmp.setRptTime(rs.getString("RPT_TIME")); snBuf.append(",").append(rs.getString("AUTO_SN")); } rs.close(); st.executeUpdate(delRPTSql + snBuf.toString() + ")"); break MISSING_BLOCK_LABEL_364; SQLException e; e; RPTItem arptitem[]; releaseConn(); if(e.getErrorCode() != 1146 && e.getErrorCode() != 1142) { break MISSING_BLOCK_LABEL_330; } arptitem = new RPTItem[0]; closeStatment(st); return arptitem; arptitem = null; closeStatment(st); return arptitem; Exception ex; ex; arptitem = null; closeStatment(st); return arptitem; Exception exception; exception; closeStatment(st); throw exception; closeStatment(st); RPTItem rptItem[] = new RPTItem[0]; return (RPTItem[])rptList.toArray(rptItem); } public RPTItem[] receiveRPT(long smID, int amount) { Statement st; String getRPTSql; String delRPTSql; ArrayList rptList; StringBuffer snBuf; if(dbUrl == null) { return null; } ResultSet rs = null; st = null; if(conn == null) { int state = initConnect(); if(state != 0) { return null; } } getRPTSql = "select * from api_rpt_" + apiCode_; if(smID != -1L) { getRPTSql = getRPTSql + " where SM_ID=" + smID; } if(amount != -1) { getRPTSql = getRPTSql + " limit " + amount; } delRPTSql = "delete from api_rpt_" + apiCode_ + " where AUTO_SN in ("; RPTItem rptItem[] = (RPTItem[])null; rptList = new ArrayList(); snBuf = new StringBuffer("-1"); st = conn.createStatement(); ResultSet rs; RPTItem rptItemtmp; for(rs = st.executeQuery(getRPTSql); rs.next(); rptList.add(rptItemtmp)) { rptItemtmp = new RPTItem(); rptItemtmp.setSmID(rs.getLong("SM_ID")); rptItemtmp.setCode(rs.getInt("RPT_CODE")); rptItemtmp.setMobile(rs.getString("MOBILE")); rptItemtmp.setDesc(rs.getString("RPT_DESC")); rptItemtmp.setRptTime(rs.getString("RPT_TIME")); snBuf.append(",").append(rs.getString("AUTO_SN")); } rs.close(); st.executeUpdate(delRPTSql + snBuf.toString() + ")"); break MISSING_BLOCK_LABEL_448; SQLException e; e; RPTItem arptitem[]; releaseConn(); if(e.getErrorCode() != 1146 && e.getErrorCode() != 1142) { break MISSING_BLOCK_LABEL_411; } arptitem = new RPTItem[0]; closeStatment(st); return arptitem; arptitem = null; closeStatment(st); return arptitem; Exception ex; ex; arptitem = null; closeStatment(st); return arptitem; Exception exception; exception; closeStatment(st); throw exception; closeStatment(st); RPTItem rptItem[] = new RPTItem[0]; return (RPTItem[])rptList.toArray(rptItem); } public void release() { dbUser = null; dbPwd = null; apiCode_ = null; dbUrl = null; releaseConn(); } private int testConnect() { Statement st; st = null; ResultSet rs = null; try { if(conn != null) { releaseConn(); } getConn(); st = conn.createStatement(); } catch(ClassNotFoundException e) { e.printStackTrace(); return -1; } catch(SQLException e) { e.printStackTrace(); return -1; } try { String tableName = "api_mo_" + apiCode_; ResultSet rs = st.executeQuery("select * from " + tableName + " limit 1"); rs.close(); } catch(SQLException e) { try { st.close(); } catch(Exception exception1) { } return -7; } break MISSING_BLOCK_LABEL_137; Exception exception; exception; try { st.close(); } catch(Exception exception2) { } throw exception; try { st.close(); } catch(Exception exception3) { } return 0; } private int initConnect() { try { getConn(); } catch(Exception e) { e.printStackTrace(); return -1; } return 0; } private void getConn() throws ClassNotFoundException, SQLException { Class.forName("org.gjt.mm.mysql.Driver"); conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd); } private void releaseConn() { if(conn != null) { try { conn.close(); } catch(SQLException sqlexception) { } } conn = null; } private int mTInsert(String mobile, String content, long smID, long srcID, String url, String sendTime) { String sendMTSql; Statement st; if(conn == null) { int state = initConnect(); if(state != 0) { return -1; } } if(sendTime == null || "".equals(sendTime)) { sendTime = getCurDateTime(); } sendMTSql = ""; if(url == null || url.trim().length() == 0) { sendMTSql = "insert into api_mt_" + apiCode_ + " (SM_ID,SRC_ID,MOBILES,CONTENT,SEND_TIME) values (" + smID + "," + srcID + ",'" + mobile + "','" + content + "','" + sendTime + "')"; } else { sendMTSql = "insert into api_mt_" + apiCode_ + " (SM_ID,SRC_ID,MOBILES,CONTENT,IS_WAP,URL,SEND_TIME) values (" + smID + "," + srcID + ",'" + mobile + "','" + content + "'," + 1 + ",'" + url + "','" + sendTime + "')"; } st = null; try { st = conn.createStatement(); st.executeUpdate(gb2Iso(sendMTSql)); break MISSING_BLOCK_LABEL_299; } catch(SQLException e) { releaseConn(); } closeStatment(st); return -3; Exception exception; exception; closeStatment(st); throw exception; closeStatment(st); return 0; } private void closeStatment(Statement st) { try { st.close(); } catch(Exception exception) { } } private String replaceSpecilAlhpa(String content) { if(content == null || content.trim().length() == 0) { return ""; } String spec_char = "\\'"; String retStr = ""; for(int i = 0; i < content.length(); i++) { if(spec_char.indexOf(content.charAt(i)) >= 0) { retStr = retStr + "\\"; } retStr = retStr + content.charAt(i); } return retStr; } private boolean checkSmID(long smID) { return smID >= 0L && smID <= 0x5f5e0ffL; } private String gb2Iso(String str) { if(str == null) { return ""; } String temp = ""; try { byte buf[] = str.trim().getBytes("GBK"); temp = new String(buf, "iso8859-1"); } catch(UnsupportedEncodingException e) { temp = str; } return temp; } private int checkGatConn() { int ret; Statement st; String sql; ret = 1; ResultSet rs = null; st = null; if(conn == null) { initConnect(); } sql = "select if_status,conn_succ_status from tbl_api_info as api where api.if_code='" + apiCode_ + "' limit 1"; try { st = conn.createStatement(); ResultSet rs; for(rs = st.executeQuery(sql); rs.next();) { if("2".equals(rs.getString("if_status"))) { ret = -10; } if("0".equals(rs.getString("conn_succ_status"))) { ret = -11; } } rs.close(); } catch(SQLException e) { try { st.close(); } catch(Exception exception1) { } return -7; } break MISSING_BLOCK_LABEL_160; Exception exception; exception; try { st.close(); } catch(Exception exception2) { } throw exception; try { st.close(); } catch(Exception exception3) { } return ret; } public static String getCurDateTime() { SimpleDateFormat nowDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return nowDate.format(new Date()); } public static String isDateTime(String str) { if(str == null) { return null; } if(str.length() != 19) { return null; } if(str.split(" ")[0].length() != 10) { return null; } if(str.split(" ")[1].length() != 8) { return null; } int temp = Integer.parseInt(str.substring(5, 7)); if(12 < temp || temp < 1) { return null; } temp = Integer.parseInt(str.substring(8, 10)); if(31 < temp || temp < 1) { return null; } temp = Integer.parseInt(str.substring(11, 13)); if(23 < temp || temp < 0) { return null; } temp = Integer.parseInt(str.substring(14, 16)); if(59 < temp || temp < 0) { return null; } temp = Integer.parseInt(str.substring(17, 19)); if(59 < temp || temp < 0) { return null; } Date returnDate = null; DateFormat df = DateFormat.getDateInstance(); try { returnDate = df.parse(str); return returnDate.toString(); } catch(Exception e) { return null; } } }
发表评论
-
WSDL中min0ccurs和nillable的区别
2011-08-15 16:59 8241minOccurs="0" 在null的时 ... -
[转]利用Spring的AOP机制配置管理EHCache
2010-05-27 09:17 1443如果我们的项目中采用的是Spring+hibern ... -
[转]Hibernate的proxool连接池参数
2010-05-20 18:05 1231Example configuration: <p ... -
[转]Spring几种获取Bean的方式
2010-05-20 08:34 1353获得spring里注册Bean的四种方法,特别是第三种方法,简 ... -
[转]Spring中ApplicationContext的获取方式
2010-05-20 08:29 982Spring中ApplicationContext加载机制。 ... -
[转]Struts 2.1.x + Spring 2.5.x + Hibernate 3.3.x整合需要的JAR包
2010-05-19 08:55 1297下面这个表相信对很多人都有用: jar包名称 ... -
Spring整合Hibernate
2010-05-18 22:39 0Hibernate3.3 + Spring2.5整合 1.包 ... -
[转]Javascript解析XML文档
2010-05-11 15:41 782例如有如下XML文件: <?xml version ... -
[转]Criteria和DetachedCriteria的分别
2010-05-07 12:42 816使用 Spring 和 Hibernate 进行开发,有 ... -
Java读取properties文件的思考
2010-04-21 15:33 1165此文为转载,原文地址:http://lavasoft.blog ... -
超简单的QuartZ上手入门教程
2010-04-19 16:57 2329随便写个Job类,实现quartz的job package ... -
LRC格式转换
2008-09-12 23:36 1387import java.io.BufferedReader; ...
相关推荐
SPADE是一个开源的多代理系统(MAS)框架,用于构建分布式、协作的智能代理应用。spade_client库则为开发人员提供了一种简单的方式来连接到SPADE服务器,实现代理之间的通信。 "4.5.0.dev35"这个版本号表示这是...
6. **通知系统**:为了提醒用户即将到期的任务,客户端可能集成macOS的通知中心API,发送本地通知。 7. **版本控制**:Git是常用的版本控制系统,用于跟踪代码变更、合并分支和协作开发。"a4a26d7"代表的Git提交...
Rocky Linux 8.10内核包
内容概要:本文档详细介绍了如何在Simulink中设计一个满足特定规格的音频带ADC(模数转换器)。首先选择了三阶单环多位量化Σ-Δ调制器作为设计方案,因为这种结构能在音频带宽内提供高噪声整形效果,并且多位量化可以降低量化噪声。接着,文档展示了具体的Simulink建模步骤,包括创建模型、添加各个组件如积分器、量化器、DAC反馈以及连接它们。此外,还进行了参数设计与计算,特别是过采样率和信噪比的估算,并引入了动态元件匹配技术来减少DAC的非线性误差。性能验证部分则通过理想和非理想的仿真实验评估了系统的稳定性和各项指标,最终证明所设计的ADC能够达到预期的技术标准。 适用人群:电子工程专业学生、从事数据转换器研究或开发的技术人员。 使用场景及目标:适用于希望深入了解Σ-Δ调制器的工作原理及其在音频带ADC应用中的具体实现方法的人群。目标是掌握如何利用MATLAB/Simulink工具进行复杂电路的设计与仿真。 其他说明:文中提供了详细的Matlab代码片段用于指导读者完成整个设计流程,同时附带了一些辅助函数帮助分析仿真结果。
内容概要:该题库专为研究生入学考试计算机组成原理科目设计,涵盖名校考研真题、经典教材课后习题、章节题库和模拟试题四大核心模块。名校考研真题精选多所知名高校的计算机组成原理科目及计算机联考真题,并提供详尽解析,帮助考生把握考研命题趋势与难度。经典教材课后习题包括白中英《计算机组成原理》(第5版)和唐朔飞《计算机组成原理》(第2版)的全部课后习题解答,这两部教材被众多名校列为考研指定参考书目。章节题库精选代表性考题,注重基础知识与重难点内容,帮助考生全面掌握考试大纲要求的知识点。模拟试题依据历年考研真题命题规律和热门考点,精心编制两套全真模拟试题,并附标准答案,帮助考生检验学习成果,评估应试能力。 适用人群:计划参加研究生入学考试并报考计算机组成原理科目的考生,尤其是需要系统复习和强化训练的学生。 使用场景及目标:①通过研读名校考研真题,考生可以准确把握考研命题趋势与难度,有效评估复习成效;②通过经典教材课后习题的练习,考生可以巩固基础知识,掌握解题技巧;③通过章节题库的系统练习,考生可以全面掌握考试大纲要求的各个知识点,为备考打下坚实基础;④通过模拟试题的测试,考生可以检验学习成果,评估应试能力,为正式考试做好充分准备。 其他说明:该题库不仅提供详细的题目解析,还涵盖了计算机组成原理的各个方面,包括计算机系统概述、数据表示与运算、存储器分层、指令系统、中央处理器、总线系统和输入输出系统等。考生在使用过程中应结合理论学习与实践操作,注重理解与应用,以提高应试能力和专业知识水平。
__UNI__DB9970A__20250328141034.apk.1
rust for minio
国网台区终端最新规范
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
一个简单的机器学习代码示例,使用的是经典的鸢尾花(Iris)数据集,通过 Scikit-learn 库实现了一个简单的分类模型。这个代码可以帮助你入门机器学习中的分类任务。
pyqt离线包,pyqt-tools离线包
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
SQL常用日期和时间函数整理及在sqlserver测试示例 主要包括 1.查询当前日期GETDATE 2.日期时间加减函数DATEADD 3 返回两个日期中指定的日期部分之间的差值DATEDIFF 4.日期格式转换CONVERT(VARCHAR(10),GETDATE(),120) 5.返回指定日期的年份数值 6.返回指定日期的月份数值 7.返回指定日期的天数数值
GSDML-V2.3-Turck-BL20_E_GW_EN-20160524-010300.xml
T_CPCIF 0225-2022 多聚甲醛.docx
《基于YOLOv8的智能仓储货物堆码倾斜预警系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计
蚕豆脱壳机设计.zip
台区终端电科院送检文档
Y6一39一No23.6D离心通风机 CAD().zip
django自建博客app