- 浏览: 194602 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
shuaijie506:
以前有点疑惑,现在终于明白了,线程安全是没问题的,想想也是,如 ...
jsp自定义标签 线程安全 -
Laster2800:
原来如此,想不到传统的标记处理器也是线程安全的,受教了。
jsp自定义标签 线程安全 -
GoingForward:
这篇文章是不是可以浓缩为下面几点:1.在非静态内部类中不可以声 ...
static class -
wellse:
呵呵,就是这样!!要的就是这个效果
jsp自定义标签 线程安全 -
xiaohuafyle:
JNDI
import java.sql.Connection; import java.sql.DriverManager; public class ConnectSybase { public static void main(String []args) throws Exception{ Class.forName("com.sybase.jdbc2.jdbc.SybDriver"); // con=os.getConnection(); System.out.println("OK"); Connection co = DriverManager.getConnection( "jdbc:sybase:Tds:10.17.34.188:5000/spms", "sa",""); if (co != null) { System.out.println(co); } } }
/** * <p>Title:Tool </p> * <p>Description:工具类,常用的方法 </p> * <p>Copyright:(c) </p> * <p>Company: eshore </p> * @author lik * @version 1.0 */ import java.awt.Dimension; import java.awt.Toolkit; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; import java.text.DateFormat; import java.text.ParseException; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.StringTokenizer; import java.util.Vector; import java.util.zip.DataFormatException; import javax.servlet.http.HttpServletRequest; import sun.io.ByteToCharConverter; import sun.io.CharToByteConverter; public class Tool { public Tool() { } /** * 将源对象中与目标对象中相等的字段的值复制到目标对象中 * @param pSource Object 源对象 * @param pTarget Object 目标对象 */ public static void copyValue(Object pSource, Object pTarget) { Object tReturn = null; try { //获得所有的属性 Field[] fields = pSource.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field fiel = fields[i]; String name = fiel.getName(); String tName = null; try { pTarget.getClass().getDeclaredField(name); } catch (Exception ex) { Debug.print(ex); continue; } Debug.println("method name is " + name); Class type = fiel.getType(); String setMethodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length()); String getMethodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length()); Class[] param = { type}; Debug.println("returntype is" + type.getName() + "ff " + getMethodName); Method setMethoded = null; try { setMethoded = pTarget.getClass().getDeclaredMethod(setMethodName, param); Debug.println("------method is" + setMethoded.getName()); Method getMethoded = null; getMethoded = pSource.getClass().getDeclaredMethod(getMethodName, null); Debug.println("====method is" + getMethoded.getName()); Object[] params = {}; tReturn = getMethoded.invoke(pSource, params); Object[] paramReturn = { tReturn}; setMethoded.invoke(pTarget, paramReturn); } catch (Exception ex) { Debug.println("de get method catch" + ex); continue; } } //end for } catch (Exception ex) { Debug.println("insert catch" + ex); } } /** * 该函数将在指定的字符前插入一个字符 * @param pSource String 要替换的字符串 * @param pOb char 指定的字符 * @param pAcc char 要插入的字符 * @return String 处理好的字符串 */ public static String tranString(String pSource, char pOb, char pAcc) { if (pSource == null || pSource.equals("")) return ""; String strTmp = ""; int flag = pSource.indexOf(pOb); String strM = new String(pSource); if (flag != -1) { while (true) { if (flag > 0) { strTmp = strTmp + strM.substring(0, flag) + pAcc + pOb; } else { strTmp = strTmp + pAcc + pOb; } if (flag >= strM.length()) { break; } else { strM = strM.substring(flag + 1); flag = strM.indexOf(pOb); if (flag == -1) { break; } } } return strTmp; } else { return pSource; } } /** * 该函数将在指定的字符串中特定替换成新的字符串 * @param rStr String 指定字符串 * @param rFix String 要替换的字符串 * @param rRep String 要替换成的字符串 * @return String 已替换的字符串 */ public static String StrReplace(String line, String oldString, String newString) { if (line == null) { return null; } int i = 0; if ( (i = line.indexOf(oldString, i)) >= 0) { char[] line2 = line.toCharArray(); char[] newString2 = newString.toCharArray(); int oLength = oldString.length(); StringBuffer buf = new StringBuffer(line2.length); buf.append(line2, 0, i).append(newString2); i += oLength; int j = i; while ( (i = line.indexOf(oldString, i)) > 0) { buf.append(line2, j, i - j).append(newString2); i += oLength; j = i; } buf.append(line2, j, line2.length - j); return buf.toString(); } return line; } public static String replaceIgnoreCase(String line, String oldString, String newString) { if (line == null) { return null; } String lcLine = line.toLowerCase(); String lcOldString = oldString.toLowerCase(); int i = 0; if ( (i = lcLine.indexOf(lcOldString, i)) >= 0) { char[] line2 = line.toCharArray(); char[] newString2 = newString.toCharArray(); int oLength = oldString.length(); StringBuffer buf = new StringBuffer(line2.length); buf.append(line2, 0, i).append(newString2); i += oLength; int j = i; while ( (i = lcLine.indexOf(lcOldString, i)) > 0) { buf.append(line2, j, i - j).append(newString2); i += oLength; j = i; } buf.append(line2, j, line2.length - j); return buf.toString(); } return line; } /** * 从request中封装一个对象 * @param pRequest HttpServletRequest request对象 * @param pModel Class 封装对象的类 * @return Object 超类 * @throws Exception */ public static Object getParameter(HttpServletRequest pRequest, Class pModel) throws Exception { Object tReturn = null; tReturn = pModel.newInstance(); //获得所有的属性 Field[] fields = pModel.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { try { Field fiel = fields[i]; String name = fiel.getName(); Class type = fiel.getType(); String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length()); Debug.println("方法名:" + methodName); Object returnValue = null; Object[] paras = {}; Class[] para = { type}; Method methoded = pModel.getDeclaredMethod(methodName, para); Class[] returnTypes = methoded.getParameterTypes(); Class returnType = returnTypes[0]; returnValue = pRequest.getParameter(name); if (returnType == java.lang.String.class) { if (returnValue != null) { returnValue = ( (String) returnValue).trim(); } } else if ( (returnType == int.class) || (returnType == Integer.class)) { if (returnValue != null) { try { returnValue = new Integer(Integer.parseInt( (String) returnValue)); } catch (NumberFormatException ex1) { returnValue = new Integer(0); } } } else if ( (returnType == double.class) || (returnType == Double.class)) { if (returnValue != null) { returnValue = new Double(Double.parseDouble( (String) returnValue)); } } else if (returnType == java.util.Collection.class) { String[] pars = pRequest.getParameterValues(name); if (pars != null && pars.length > 0) { ArrayList li = new ArrayList(); for (int j = 0; j < pars.length; j++) { li.add(pars[j]); Debug.println("id is " + pars[j]); } returnValue = li; } } else if ( (returnType == float.class) || (returnType == Float.class)) { if (returnValue != null) { returnValue = new Float(Float.parseFloat( (String) returnValue)); } } else if (returnType == java.util.Date.class) { if (returnValue != null) { try { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateTmp = (String) returnValue; if (dateTmp.length() < 11) { returnValue = dateTmp + " 00:00:00"; } returnValue = formatter.parse( (String) returnValue); } catch (Exception ex) { Debug.println(ex); } } } else if (returnType == java.sql.Date.class) { if (returnValue != null) { try { DateFormat df = DateFormat.getDateInstance(); returnValue = new java.sql.Date(df.parse( (String) returnValue).getTime()); } catch (Exception ex) { Debug.print(ex); } } } else { Debug.println("没有处理的类型 " + returnType.getName()); } Object[] params = { returnValue}; methoded.invoke(tReturn, params); } catch (Exception ex) { ex.printStackTrace(); Debug.println("invoke catch:" + ex.getMessage()); } } return tReturn; } /** * 将ISO8859_1字符转为gb2312编码 * @param pStr String 要进行转码的字符 * @return String 转码后的字符 */ public static String convertEncoding(String pStr) { String target = pStr; if (target != null) { try { target = new String(pStr.getBytes("8859_1"), "gb2312"); } catch (Exception e) { Debug.println("转码失败!"); } } return target; } /** * 将ISO8859_1字符转为gb2312编码 * @param pStr String 要进行转码的字符 * @return String 转码后的字符 */ public static String unConvertEncoding(String pStr) { String target = pStr; try { target = new String(pStr.getBytes("gb2312"), "8859_1"); } catch (Exception e) { Debug.println("转码失败!"); } return target; } /** * 按时间得到随机数 * @return string 随机数 */ public static String getRandom() { java.util.Date date = new java.util.Date(); return (date.getTime() + "").substring(2); } /** * 此方法为一种对回车换行的翻译为相关代码值的方法,用<pre></pre>可以搞定 * @param string String 要处理的字符串 * @return String 处理后的字符串 */ public static String translateString(String string) { String returnStr = ""; int begin = 0; char c[] = { '\r', '\n', '\r', '\n', '\r', '\n'}; String str = new String(c); int index = string.indexOf(str); String sub = new String(); if (index != -1) sub = string.substring(index + 6, string.length()); else sub = string; index = 0; Vector vc = new Vector(); char c1[] = { '\r', '\n'}; String str1 = new String(c1); index = sub.indexOf(str1); while (index != -1) { String s = sub.substring(0, index); vc.addElement(s); sub = sub.substring(index + 1, sub.length()); index = sub.indexOf(str1); } String s = sub.substring(begin); vc.addElement(s); if (!vc.isEmpty()) { int count1 = vc.size(); for (int k = 0; k < count1; k++) returnStr = returnStr + (String) vc.elementAt(k) + "<br>"; } return returnStr; } /** * 截取字符串,可以处理中,英的问题 * @param sourceString String 待处理的字符串 * @param length int 截取的长度,是字节长度,一个中文两个字节 * @return String 返回截取后的字符串 */ public static String substring(String sourceString, int length) { char[] sourceChrs = sourceString.toCharArray(); char[] distinChrs = new char[length]; for (int i = 0; i < length; i++) { if (i >= sourceChrs.length) { break; } Character chr = new Character(sourceChrs[i]); if (chr.charValue() <= 202 && chr.charValue() >= 8) { distinChrs[i] = chr.charValue(); } else { distinChrs[i] = chr.charValue(); length--; } } return new String(distinChrs); } /** * 判断字符串长度是否大于给定字节长度,可以处理中,英文的问题, * ( 与上面的 substring 配合使用 ) * @param sourceString String 待比较的字符串 * @param length int 给定的字节长度,是字节长度,一个中文两个字节 * @return boolean 判断后的结果 如果大于返回true,否则返回 false */ public static boolean longThen(String sourceString, int length) { int index = 0; char[] sourceChrs = sourceString.toCharArray(); int sourceLength = sourceChrs.length; for (int i = 0; i < sourceLength; i++) { Character chr = new Character(sourceChrs[i]); if (chr.charValue() <= 202 && chr.charValue() >= 8) { index++; } else { index += 2; } } return index > length; } /** * 截取字符串,可以处理中,英的问题 + "…" * @param sourceString String 待处理的字符串 * @param length int 截取的长度,是字节长度,一个中文两个字节 * @return String 返回截取后的字符串 */ public static String subAdd(String sourceString, int length) { char[] sourceChrs = sourceString.toCharArray(); char[] distinChrs = new char[length]; for (int i = 0; i < length; i++) { if (i >= sourceChrs.length) { return sourceString; } Character chr = new Character(sourceChrs[i]); if (chr.charValue() <= 202 && chr.charValue() >= 8) { distinChrs[i] = chr.charValue(); } else { distinChrs[i] = chr.charValue(); length--; } } return new String(distinChrs) + "…"; } /** * 字符串自动换行,可以处理中,英的问题 * @param sourceString String 待处理的字符串 * @param length int 每行的字节长度,是字节长度,一个中文两个字节 * @return String 返回经过换行后的字符串 */ public static String autoNewLine(String sourceString, int length) { String destinStr = ""; char[] sourceChrs = sourceString.toCharArray(); int sourceLeanth = sourceChrs.length; int rowLeanth = 0; int index = 0; while (true) { rowLeanth = length; char[] distinChrs = new char[rowLeanth]; for (int i = 0; i < rowLeanth; i++) { if (index >= sourceLeanth) { break; } Character chr = new Character(sourceChrs[index]); index++; if (chr.charValue() <= 202 && chr.charValue() >= 8) { distinChrs[i] = chr.charValue(); } else { distinChrs[i] = chr.charValue(); rowLeanth--; } } destinStr = destinStr + (new String(distinChrs)) + "<br>"; if (index >= sourceLeanth) { break; } } return destinStr.substring(0, destinStr.length() - 4); //new String(distinChrs); } /** * 得到字符串长度,可以处理中,英文的问题, * @param sourceString String 待测量的字符串 * @return int 得到的字节长度,是字节长度,一个中文两个字节 * @author zhaoqs */ public static int getLength(String sourceString) { int index = 0; char[] sourceChrs = sourceString.toCharArray(); int sourceLength = sourceChrs.length; for (int i = 0; i < sourceLength; i++) { Character chr = new Character(sourceChrs[i]); if (chr.charValue() <= 202 && chr.charValue() >= 8) { index++; } else { index += 2; } } return index; } /** * 格式化字符串,在字符串两端添加指定字符,已达到指定长度,比如:源串为“公司公告” * length 为 22,formatChr 为 “-”,则得到字符串 -----公司公告---- * @param String sourceString 待格式的字符串 * @param int length 给定的字节长度,是字节长度,一个中文两个字节 * @return string 格式后的结果 * @author zhaoqs */ public static String formatString(String sourceString, int length, String formatChr) { int index = 0; int sourceLen = getLength(sourceString); int formatLen = getLength(formatChr); int loopInt = (length - sourceLen) / (2 * formatLen); String formatStr = ""; for (int i = 0; i < loopInt; i++) { formatStr += formatChr; } return formatStr + sourceString + formatStr; } /* public static int copyStream(InputStream in, OutputStream out) throws IOException { int result = 0; byte[] buf = new byte[8 * 1024]; for (; ; ) { int numRead = in.read(buf); if (numRead == -1) break; out.write(buf, 0, numRead); result += numRead; } out.flush(); return result; } public static byte[] getStreamBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Tools.copyStream(in, out); return out.toByteArray(); } */ /** * 从输入流中封装一个byte[] * @param stream InputStream 输入流 * @throws IOException * @return byte[] byte数组 */ public static byte[] getStreamBytes(InputStream stream) throws IOException { BufferedInputStream bis = new BufferedInputStream(stream); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); byte[] buffer = new byte[8 * 1024]; int readCount; while ( (readCount = bis.read(buffer)) > 0) { bos.write(buffer, 0, readCount); } bos.close(); bis.close(); stream.close(); byte[] tContent = baos.toByteArray(); baos.close(); baos = null; bos = null; stream = null; bis = null; return tContent; } /** * 删除文件夹 * @param String filePath 待删除文件夹路径 * @throws Exception */ public static void delfileTree(String filePath) throws Exception { java.io.File file = new java.io.File(filePath); if (file.isDirectory()) { //删除子目录 String[] filelist = file.list(); //列出所有的子文件(夹)名字 for (int i = 0; i < filelist.length; i++) { delfileTree(filePath + "\\" + filelist[i]); //System.out.println(filelist[i]+"是树"); } } else { //删除文件 file.delete(); //System.out.println("删除"+file); } file.delete(); //删除该文件夹 } /** * 转换邮件中title的乱码,例如: * (=?GB2312?Q?Fw: 2002=D1=D0=CC=D6=BB=E1=B6=AF=D4=B1=B4=F3=BB=E1=F4=DF=C7= * E9=BF=F6=CD=A8=B1=A8=A3=A8=BB=E1=D2=E9=BC=C7=C2=BC=A3=A9?=) * @param str 待转换字符串 * @return String 转换好的字符串 */ public static String mailTitleConverter(String str) { String tReturn = str; StringBuffer temp = new StringBuffer().append(str); if (str != null) { int ii = 0; //System.out.println("##############################"); Debug.println("原码:" + str); String str2 = str.toUpperCase(); if ( ( (ii = str2.indexOf("=?GB2312?Q?")) != -1) || ( (ii = str2.indexOf("=?GB2312?B?")) != -1) || ( (ii = str2.indexOf("=?ISO-8859-1?Q?")) != -1) || ( (ii = str2.indexOf("=?ISO-8859-1?B?")) != -1) || ( (ii = str2.indexOf("=?BIG5?Q?")) != -1) || ( (ii = str2.indexOf("=?BIG5?B?")) != -1) || ( (ii = str2.indexOf("=?US-ASCII?Q?")) != -1) || ( (ii = str2.indexOf("=?US-ASCII?B?")) != -1) || ( (ii = str2.indexOf("=?UNICODE-1-1-UTF-7?Q?")) != -1) || ( (ii = str2.indexOf("=?UNICODE-1-1-UTF-7?B?")) != -1)) { str = null; str = temp.toString(); str = Tool.replaceIgnoreCase(str, "=?us-ascii?Q?", ""); str = Tool.replaceIgnoreCase(str, "=?us-ascii?B?", ""); str = Tool.replaceIgnoreCase(str, "=?big5?Q?", ""); str = Tool.replaceIgnoreCase(str, "=?big5?B?", ""); str = Tool.replaceIgnoreCase(str, "=?ISO-8859-1?Q?", ""); str = Tool.replaceIgnoreCase(str, "=?ISO-8859-1?B?", ""); str = Tool.replaceIgnoreCase(str, "=?GB2312?Q?", ""); str = Tool.replaceIgnoreCase(str, "=?GB2312?B?", ""); str = Tool.replaceIgnoreCase(str, "=?UNICODE-1-1-UTF-7?Q?", ""); str = Tool.replaceIgnoreCase(str, "=?UNICODE-1-1-UTF-7?B?", ""); str = Tool.replaceIgnoreCase(str, "?=", ""); byte[] main = str.getBytes(); byte[] remain = new byte[main.length]; //System.out.println("截取后:"+new String(main)); //System.out.println("##############################"); int index = 0; int i = 0; while (index < main.length) { if (main[index] == '=') { index++; byte a1 = main[index]; if (a1 >= 65) { a1 -= 55; } else { a1 -= 48; } index++; byte a2 = main[index]; if (a2 >= 65) { a2 -= 55; } else { a2 -= 48; } remain[i] = (byte) (a1 * 16 + a2); index++; i++; } else { remain[i] = main[index]; i++; index++; } } str = null; str = new String(remain).substring(0, i); } } return str; } /** * 转码函数:String到UNICODE * @param u String 待转字符串 * @return String 转好字符串 */ public static String uCode(String u) { int iLen = u.length(); String c; String cStr = ""; int k; if (iLen == 0) return ""; for (int i = 0; i < iLen; i++) { c = u.substring(i, i + 1); k = c.hashCode(); if (k > 255) cStr = cStr + String.valueOf( (char) (k >> 8)) + String.valueOf( (char) (k & 255)); else cStr = cStr + String.valueOf( (char) 0) + c; } return cStr; } /** * 转码函数:UNICODE到CHAR * @param str String 待转字符串 * @return String 转好字符串 */ public static String uDCode(String str) { int iLen = str.length(); if (iLen % 2 != 0) return "-1"; String Out = ""; for (int i = 0; i < iLen / 2; i++) Out = Out + String.valueOf( (char) ( ( ( (int) str.charAt(i * 2)) << 8) + (int) str.charAt(i * 2 + 1))); return Out; } /** * 内部加密函数 * @param str String 待加密的字符串 * @return String 已加密的字符串 */ public static String encode(String str) { if (str == null) return null; int iLen = str.length(); if (iLen == 0) return ""; str = uCode(str); iLen = str.length(); String tempStr1, tempStr2, tempStr3; String tempOut = ""; String Out = ""; Random r = new Random(); int l = 0; for (int n = 0; n < iLen; n++) { tempStr1 = Integer.toHexString( (str.substring(n, n + 1).hashCode()) >> 4); tempStr2 = Integer.toHexString( (str.substring(n, n + 1).hashCode()) & 15); tempStr3 = Integer.toString(r.nextInt()); tempStr3 = tempStr3.substring(tempStr3.length() - 1, tempStr3.length()); if (n % 3 == 0) tempOut = tempOut + tempStr3 + tempStr1 + tempStr2; else if (n % 3 == 1) tempOut = tempOut + tempStr1 + tempStr3 + tempStr2; else tempOut = tempOut + tempStr1 + tempStr2 + tempStr3; } return tempOut; } /** * 内部解密的函数 * @param str String 待解密的字符串 * @return String 已解密的字符串 */ public static String decode(String str) { if (str == null) return null; int iLen = str.length(); if (iLen == 0) return ""; //密码为空 String tStr = ""; //临时字符串 String hexStr = ""; //16进制字符串 String Out = ""; hexStr = str; if (hexStr.length() % 3 != 0) return "-1"; for (int i = 0; i < hexStr.length() / 3; i++) if (i % 3 == 0) tStr = tStr + hexStr.substring(i * 3 + 1, (i + 1) * 3); else if (i % 3 == 1) tStr = tStr + hexStr.substring(i * 3, i * 3 + 1) + hexStr.substring(i * 3 + 2, (i + 1) * 3); else tStr = tStr + hexStr.substring(i * 3, i * 3 + 2); for (int i = 0; i < tStr.length() / 2; i++) Out = Out + String.valueOf( (char) ( ( (Char2int(tStr.charAt(i * 2))) << 4) + Char2int(tStr.charAt(i * 2 + 1)))); Out = uDCode(Out); return Out; } /** * 16进制字符转换为10进制数值 * @param s char 代转字符 * @return int 转换后10进制数值 */ public static int Char2int(char s) { if (s >= '0' && s <= '9') { return s - '0'; } else if (s >= 'a' && s <= 'f') { return s - 'a' + 10; } else { return -1; } } /** * 根据","分隔符来取列表 * @param str String 待取字符串 * @return List 取得的字符串列表 */ public static List stringParseToList(String str) { List tempArrList = new ArrayList(); StringTokenizer st = new java.util.StringTokenizer(str, ","); while (st.hasMoreTokens()) { tempArrList.add(st.nextToken()); } return tempArrList; } /** * 根据传入参数分隔符来取列表 * @param str String 待取字符串 * @param sign String 分隔符 * @return List 取得的字符串列表 */ public static List stringParseToList(String str, String sign) { List tempArrList = new ArrayList(); StringTokenizer st = new java.util.StringTokenizer(str, sign); while (st.hasMoreTokens()) { tempArrList.add(st.nextToken()); } return tempArrList; } /** * 根据 ",","."分隔符来取List二维列表 * @param str String 待取字符串 * @return List 取得的字符串列表 */ public static List _stringParseToList(String str) { List tempArrList = new ArrayList(); StringTokenizer st = new java.util.StringTokenizer(str, ","); while (st.hasMoreTokens()) { String strvalue = st.nextToken(); StringTokenizer st1 = new java.util.StringTokenizer(strvalue, "."); List tempList = new ArrayList(); while (st1.hasMoreTokens()) { tempList.add(st1.nextToken()); } if ( (tempList != null) && (tempList.size() > 0)) { tempArrList.add(tempList); } } return tempArrList; } /** * 根据时间返回8位随机数 */ public static String getSeed() { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); return format.format(new Date()); } /** * 过滤特殊字符,转换为标准html格式 * @param input String 待过滤的字符串 * @return String 过滤好的字符串 */ public static String escapeHTMLTags(String input) { String returnStr = ""; if (input == null || input.length() == 0) { return returnStr; } else { StringBuffer buf = new StringBuffer(); for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); if (ch == '<') { buf.append("<"); } else if (ch == '>') { buf.append(">"); } else if (ch == '"') { buf.append("""); } else if (ch == '&') { buf.append("&"); } else if (ch == ' ') { buf.append(" "); } else { buf.append(ch); } } returnStr = buf.toString(); String tempStr = ""; StringTokenizer strToken = new StringTokenizer(buf.toString(), "\n"); while (strToken.hasMoreTokens()) { if (tempStr.length() > 0) tempStr = tempStr + "<br>" + strToken.nextToken(); else tempStr = strToken.nextToken(); } returnStr = tempStr; } return returnStr; } /** * 处理null的字符串,返回"" * @param str String 待处理的字符串 * @return String 处理好的字符串 */ public static String isNull(String str) { return str == null ? "" : str; } /** * 取显示器屏幕的宽度 * @return int 宽度,单位是象素 */ public static int getScreenWidth() { int width = 800; Toolkit tk = Toolkit.getDefaultToolkit(); Dimension ds = tk.getScreenSize(); width = ds.width; return width; } /** * 获得n位随机数 * @param length int 要生成随机数的位数 * @return String 随机数 */ public synchronized final static String generateId(int length) { Random random = new Random(); StringBuffer result = new StringBuffer(); for (int i = 0; i < length; i++) { result = result.append(random.nextInt(10)); } return result.toString(); } /** * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 * 定精度,以后的数字四舍五入。 * @param v1 被除数 * @param v2 除数 * @param scale 表示表示需要精确到小数点以后几位。 * @return 两个参数的商 */ public static double div(double v1, double v2, int scale) { if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); } BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); } /** * 获得随机数8位,从a-z,A-Z,0-9中取 * @return String 随机数 */ public static String getRandomStr() { RandomStrg random = new RandomStrg(); String tReturn = ""; try { random.setCharset("a-zA-Z0-9"); random.generateRandomObject(); tReturn = random.getRandom(); } catch (Exception e) { Debug.println("get random fail."); } return tReturn; } /** * 功能:辅助完成待查数据的去舍 * @param dTransDT String 实际余额日期 * @param dGetBalanceDT String 取余额时间 * @return boolean true:该数据是正确数据;false:该数据还待确定 */ public static boolean checkDate(String dTransDT, String dGetBalanceDT) { if (dTransDT == null || dGetBalanceDT == null) return false; SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dTransDTS = ""; String dGetBalanceDTS = ""; Date dTransDTD = null; Date dGetBalanceDTD = null; try { //取实际余额日期的年月日 dTransDTS = dTransDT.trim().substring(0, 10); // Debug.println("checkDate() -- 1." + dTransDTS); //实际余额日期加一天 dTransDTD = df1.parse(dTransDTS); Calendar calendar = Calendar.getInstance(); calendar.setTime(dTransDTD); calendar.add(5, 1); dTransDTD = calendar.getTime(); // Debug.println("checkDate() -- 2." + dTransDTD); //取取余额时间的年月日 dGetBalanceDTD = df1.parse(dGetBalanceDT); // System.out.println("checkDate() -- 3." + dGetBalanceDTD); //取余额时间 - 实际余额日期加一天 long diff = dGetBalanceDTD.getTime() - dTransDTD.getTime(); if (diff < 0) return false; //取余额时间 dGetBalanceDTD = df2.parse(dGetBalanceDT); // Debug.println("checkDate() -- 4." + dGetBalanceDTD); //应该的取余额时间 dTransDTS = df2.format(dTransDTD).trim().substring(0, 10); dTransDTD = df2.parse(dTransDTS + " 12:00:00"); // Debug.println("checkDate() -- 5." + dTransDTD); //取余额时间 - 应该的取余额时间 diff = dGetBalanceDTD.getTime() - dTransDTD.getTime(); // Debug.println("checkDate() -- 6." + diff); if (diff < 0) return false; } catch (ParseException pe) { return false; } return true; } /** * 返回浮点数的绝对值 * @param s double 待处理数 * @return double 待处理数的绝对值 */ public static double abs(double s) { if (s < 0) s = 0 - s; return s; } // public static void main(String[] args) { // Tool tool = new Tool(); // tool.delPic("D:/jboss-3.2.3/server/default/deploy/TFMS.war/images/count/", // "Mnager"); // } public static String dateToString(Date inputDate, String fmt) { if (inputDate == null) return ""; SimpleDateFormat theDateFormat = new SimpleDateFormat(fmt); return theDateFormat.format(inputDate); } public static Date stringToDate(String input, String format) throws DataFormatException { Date result = null; SimpleDateFormat theDateFormat = new SimpleDateFormat(format); if (input==null) { throw new DataFormatException("Null Value"); } try { ParsePosition pos = new ParsePosition(0); result = theDateFormat.parse(input, pos); } catch (Exception e) { throw new DataFormatException("Wrong Format"); } return result; } public static String stringsToSQL(String[] strings){ if (strings==null||strings.length==0){ return null; } StringBuffer sb=new StringBuffer(); for (int i=0;i<strings.length;i++){ if (i!=0) sb.append(","); sb.append("'").append(strings[i]).append("'"); } return sb.toString(); } private static boolean isNullObj(Object obj){ if (obj==null) return true; if (obj instanceof String){ if ("".equals(obj)) return true; if ("null".equals(obj)) return true; if ("--全部--".equals(obj)) return true; if ("0".equals(obj)) return true; } return false; } /*返回当前日期 前指定月份的日期 例如month_i=3 当前日期2005-9-10 返回 2005-06-01 * */ public static String getBeforeMonthStr(int month_i){ Date date = new Date(); String year = (new SimpleDateFormat("yyyy")).format(date); String month = (new SimpleDateFormat("M")).format(date); if(Integer.parseInt(month)-month_i>0){ try{ date = (new SimpleDateFormat("yyyy-MM-dd")).parse( year+"-"+String.valueOf(Integer.parseInt(month)-month_i)+"-01"); }catch(Exception ex){ date = new Date(); } }else{ year=Integer.parseInt(year)-1+""; try{ date = (new SimpleDateFormat("yyyy-MM-dd")).parse( year+"-"+String.valueOf(12+Integer.parseInt(month)-month_i)+"-01"); }catch(Exception ex){ date = new Date(); } } return (new SimpleDateFormat("yyyy-MM-dd")).format(date); } public static Map getStockIOTypeName(){ Map namelist=new HashMap(); namelist.put("A_01","订购入库"); namelist.put("B_01","维修转送"); namelist.put("B_02","维修接收"); namelist.put("B_03","维修送厂"); namelist.put("B_04","维修厂家返回"); namelist.put("B_05","维修返回用户"); namelist.put("B_06","维修返回入库"); namelist.put("C_01","借用出库"); namelist.put("C_02","借用入库"); namelist.put("C_03","借用返回"); namelist.put("C_04","借用返回入库"); namelist.put("C_05","厂家借用入库"); namelist.put("C_06","返回厂家出库"); namelist.put("D_01","调拨出库"); namelist.put("D_02","调拨入库"); namelist.put("D_03","工程移交入库"); namelist.put("E_01","报废出库"); namelist.put("F_01","盘点盘亏出库"); namelist.put("F_02","盘点盘盈入库"); namelist.put("G_00","扩容领用出库"); namelist.put("G_01","故障领用出库"); namelist.put("G_02","领用返回入库"); namelist.put("G_03","坏板修复领用出库"); namelist.put("H_00","初始入库"); namelist.put("H_01","坏板入库"); namelist.put("H_02","其他入库"); namelist.put("H_03","其它出库"); namelist.put("H_04","其它临时出库"); namelist.put("H_05","其它临时出库返回"); namelist.put("H_06","其它临时入库"); namelist.put("H_07","其它临时入库返回"); return namelist; } /** * 格式化数字 * @param num 数字 * @param bitcount 小数位数 * @return */ public static String ForMatNum(float num,int bitcount){ String partern="0."; for (int i=0;i<bitcount;i++) partern=partern+"0"; java.text.DecimalFormat df=new java.text.DecimalFormat(partern); return df.format(num); } public static String strISO1ToGB2312(String s) { if(s == null) return ""; char orig[] = s.toCharArray(); byte dest[] = new byte[orig.length]; for(int i = 0; i < orig.length; i++) dest[i] = (byte)(orig[i] & 0xff); try { ByteToCharConverter toChar = ByteToCharConverter.getConverter("gb2312"); String s1 = new String(toChar.convertAll(dest)); return s1; } catch(Exception e) { System.out.println(e); } String s2 = s; return s2; } public static String strGB2312ToISO1(String s) { if(s == null) return ""; try { CharToByteConverter toByte = CharToByteConverter.getConverter("gb2312"); byte orig[] = toByte.convertAll(s.toCharArray()); char dest[] = new char[orig.length]; for(int i = 0; i < orig.length; i++) dest[i] = (char)(orig[i] & 0xff); String s2 = new String(dest); return s2; } catch(Exception e) { System.out.println(e); } String s1 = s; return s1; } }
发表评论
-
Jetty例子
2010-11-07 22:04 1542import java.io.IOException; ... -
排序面试算法
2010-09-08 08:43 1696从大学到现在,参加过很多面试,经常会被问到一些基本的算法题, ... -
IReport一些注意
2010-09-05 22:02 1408用的是 Ireport2.0版本 更高版本可能没有这个问题 ... -
jsp自定义标签 线程安全
2010-08-28 14:21 4053我们在编写自定义标签的时候设置属性如下 public cl ... -
[转]Java类加载原理解析
2009-11-04 21:47 1249转载 Java 类加载原理解析 ... -
线程上下文类加载器
2009-11-04 21:46 5597线程上下文类加载器 问题:何时使用Thread. ... -
JDK 5.0 泛型 动态参数 枚举
2009-11-04 21:02 3109import java.util.ArrayList;impo ... -
再看heap 和stack,还有多了解内存
2009-11-03 16:28 1202heap 1.堆石一个“运行时”数据区,类实例化的对象就是从 ... -
java中读取Properties文件
2009-10-23 12:58 1576java 中读取Properties 文 ... -
JNI
2009-10-22 22:15 1464... -
Hibernate经典文章
2009-10-19 12:37 963Lazy Loading (Load&Get) ... -
JNDI
2009-10-15 14:15 2676最近写书,写到JNDI,到处查资料,发现所有的中文资料都对JN ... -
JDBC连接各种数据库
2009-10-14 10:13 996常用JDBC连接数据库方法总结如下: 一、DB2 Cl ... -
java并发的一些题目
2009-09-24 23:41 1077a 回答 结果又一下 几种情况 execute here Ca ... -
static class
2009-08-19 14:55 18181在一个类中创建另外 ... -
C++ 对象参数传递
2009-08-07 12:08 1689#include<iostream.h> cla ... -
递归与间接递归
2009-08-07 11:02 49361. 介绍 递归技术允许 ... -
concurrent lib的学习
2009-07-13 17:51 10681.关于BlockingQueue的学习,这是一个阻塞的队列, ... -
应该看的书籍
2009-07-12 21:33 10081.代码大全 2.人月神话 3.设计模式 4.网格计算 ... -
错误总结
2009-07-02 17:46 7911.static inner class和 non-s ...
相关推荐
标题中的“JDBC_Sybase.zip_jdbc Sybase _sybase _sybase jdbc_sybase jdbc dow”表明这是一个关于使用Java JDBC连接Sybase数据库的资源包。这个压缩文件可能包含了示例代码、数据库文件以及相关说明文档,帮助...
- `jdbc:sybase:Tds:`表示使用Sybase的TDS协议连接Sybase数据库。 - `localhost:5007`是Sybase数据库服务器的地址和端口号。 - `myDB`为数据库名称。 - **设置用户名和密码**:通过`Properties`对象设置。 - **...
Java Database Connectivity (JDBC) 是Java编程语言与各种数据库交互的标准接口,它使得Java程序员能够方便地连接到Sybase数据库进行数据操作。在本文中,我们将深入探讨Sybase数据库与JDBC驱动的相关知识点。 首先...
`jconn4`是Sybase公司提供的一种JDBC(Java Database Connectivity)驱动,主要用于帮助Java应用程序与Sybase数据库进行交互。本文将深入探讨`jconn4`驱动、其在Sybase环境中的作用以及如何使用它来建立Java到Sybase...
JDBC-sybase驱动程序.................................
根据文件内容,本篇将详细介绍在HP-UNIX操作系统环境下,如何安装和配置Sybase数据库系统。Sybase是一款成熟的商用关系型数据库管理系统,广泛应用于企业和IT领域,提供企业级的数据库服务。本篇着重于介绍Sybase ...
Sybase (ASE) jdbc 官方驱动包 (最新版), 支持ASE15.x, ASE16.x 兼容过去老版本的ASE. 用于正式的产品环境。与开源的jtds还是有区别的。 使用说明 : 将jdbc4_jdbc3.zip解压开来,使用jdbc4.jar即可。jdbc3.jar用于...
在Java应用程序中,为了与Sybase ASE数据库进行交互,开发者通常会使用JDBC(Java Database Connectivity)驱动程序。JDBC是Java平台的一个标准接口,它允许Java程序通过SQL语句与各种类型的数据库进行通信。 本...
标题中的“JTDS和JDBC连接Sybase数据库”涉及到的是Java开发中的一种数据库连接技术,主要聚焦于如何通过Java应用程序与Sybase数据库进行交互。Sybase是一种流行的关系型数据库管理系统,广泛应用于企业级应用中。...
在Java编程环境中,如果需要通过Java应用程序连接到Sybase数据库,JDBC(Java Database Connectivity)驱动是必不可少的。"sybase数据库jdbc驱动jar包"即为实现这一功能的Java库文件。 JDBC驱动是Java与各种数据库...
(Sybase jdbc 包 jconn4.jar) 连接Sybase 数据库的 一种 方式 jdbc,来给分享下 。
Sybase ASE 16 jdbc驱动包 jdbc4-1.6.0_03_26972.jar
Sybase JDBC最新驱动,带连接池
Sybase数据库jdbc驱动,Sybase数据库jdbc驱动
提供一个简单的使用Jdbc连接Sybase数据库,具体实例为: Class.forName("com.sybase.jdbc2.jdbc.SybDriver"); String url ="jdbc:sybase:Tds:IP:2638/Database"; Connection conn = DriverManager.getConnection...
标题中的“sybasejdbc合集”指的是一个包含Sybase数据库与Java进行交互的JDBC驱动程序的集合。Sybase JDBC驱动程序是Java应用程序连接到Sybase数据库的桥梁,它允许Java代码执行SQL查询,操作数据库数据,以及进行...
**Sybase 12.5.4 驱动 for JDBC 深度解析** Sybase 12.5.4 Driver for JDBC 是一个专为Java应用程序设计的数据库连接驱动,它使得Java开发者能够通过Java Database Connectivity (JDBC) API与Sybase Adaptive ...
JDBC-ODBC dirver for Sybase.
sybase 驱动 sybase 驱动 JDBC
这些驱动遵循JDBC(Java Database Connectivity)标准,使得Java开发者能够通过编写Java代码来访问和操作Sybase数据库。 此外,描述中还提到了"win32",这可能意味着压缩包内包含了适用于Windows 32位操作系统的...