- 浏览: 668291 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (297)
- J2SE (78)
- swt/飞信 (20)
- mysql/mssql (17)
- 设计模式 (5)
- windows (18)
- 闲言碎语 (19)
- struts 1.x (6)
- JVM (6)
- tomcat/jetty (8)
- jquery/javascript (15)
- web前端 (6)
- J2EE (0)
- PHP (6)
- 算法设计 (17)
- 数据结构 (3)
- C/C++ (6)
- linux (19)
- 程序打包 (8)
- eclipse/myeclipse (10)
- 其他杂项 (13)
- 应聘 (9)
- spring/spring mvc (4)
- Maven/Ant (2)
- ERROR (1)
- nosql/hbase (1)
- hibernate (3)
- Solr/Lucene (1)
最新评论
-
乔木1937:
太感谢了,看到你的文章终于解决这个问题了!
[转载]通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。 -
xianweisi:
竟然还有马
精简JRE - 实例Swing计算器 with 精简JRE(续) -
Javkburd:
我刚也遇到这个问题,然后也把默认端口改成了1433,只差最后没 ...
[转载]通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。 -
yeshaoting:
kingbinchow 写道 最近的爪哇岛 没有什么货进项呀 ...
jQuery方法区别(四)click() bind() live() delegate()区别 -
kingbinchow:
最近的爪哇岛 没有什么货进项呀!
jQuery方法区别(四)click() bind() live() delegate()区别
收藏列表
- 全部 [9]
- 默认 [8]
- java连接数据库大全 [1]
标题 | 标签 | 来源 | |
jquery怎么设置div的最大高度,然后如果超过了做大高度就显示滚动条,不然就自适应高度 | jquery怎么设置div的最大高度,然后如果超过了做大高度就显示滚动条,不然就自适应高度 | ||
var m = $(".mydiv"); m.css("height","auto"); if(m.height>400){ m.css("height","400px"); m.css("overflow","scroll"); } |
|||
JAVA操作注册表实现开机启动 | JAVA操作注册表实现开机启动 | ||
import java.awt.FlowLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.IOException; import javax.swing.JCheckBox; import javax.swing.JFrame; public class test { public void init(){ JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("测试开机启动"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox check = new JCheckBox(); check.setText("开机自动启动"); check.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { JCheckBox cb = (JCheckBox) e.getSource(); try { changeStart(cb.isSelected()); } catch (IOException e1) { e1.printStackTrace(); } } }); frame.getContentPane().add(check); //显示窗体 frame.setSize(200,300); frame.setVisible(true); } /** * Reg 参数说明 * /v 所选项之下要添加或删除的值名 * /t RegKey 数据类型(reg_sz字符串) * /d 要分配给添加的注册表 ValueName 的数据 * /f 不用提示就强行删除 */ public void changeStart(boolean isStartAtLogon) throws IOException{ String regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"; String myAppName = "MyApp"; String exePath = "D:\\Software\\eclipse\\eclipse.exe"; Runtime.getRuntime().exec("reg "+(isStartAtLogon?"add ":"delete ")+regKey+" /v "+myAppName+(isStartAtLogon?" /t reg_sz /d "+exePath:" /f")); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { new test().init(); } }); } } |
|||
mina发送数据的问题 | mina发送数据的问题 | ||
package com.nari.mina.client; import java.io.IOException; import java.net.InetSocketAddress; import org.apache.mina.core.future.ConnectFuture; import org.apache.mina.core.future.IoFutureListener; import org.apache.mina.core.service.IoConnector; import org.apache.mina.core.session.IdleStatus; import org.apache.mina.core.session.IoSession; import org.apache.mina.filter.codec.ProtocolCodecFilter; import org.apache.mina.filter.codec.textline.TextLineCodecFactory; import org.apache.mina.filter.logging.LoggingFilter; import org.apache.mina.transport.socket.nio.NioSocketConnector; import com.nari.mina.server.MyProtocalPack; public class myChatClient2 { private static final String HOST = "localhost"; private static final int PORT = 2500; static long counter = 0; final static int FC1 = 100; static long start = 0; /** * 使用Mina的框架结构进行测试 * * @param args */ public static void main(String[] args) throws IOException { start = System.currentTimeMillis(); IoConnector connector = new NioSocketConnector(); LoggingFilter lf = new LoggingFilter(); connector.getFilterChain().addLast("logger", lf); connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory())); connector.setHandler(new ChatClientHandler2()); connector.getSessionConfig().setUseReadOperation(true); connector.getSessionConfig().setReadBufferSize(100); connector.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); ConnectFuture connFuture = connector.connect(new InetSocketAddress(HOST, PORT)); connFuture.addListener(new IoFutureListener<ConnectFuture>() { public void operationComplete(ConnectFuture future) { try { if (future.isConnected()) { IoSession session = future.getSession(); sendData(session); } else { System.out.println("连接不存在 "); } } catch (Exception e) { e.printStackTrace(); } } }); System.out.println("start client ..."); } public static void sendData(IoSession session) throws IOException { for (int i = 0; i < 100; i++) { String content = "afdjkdafk张新波测试" + i; MyProtocalPack pack = new MyProtocalPack((byte) i, content); session.write(content); System.out.println("send data:" + content); } } } |
|||
java 实现 rar压缩和解压 | java 实现 rar压缩和解压 | ||
public class RarToFile { /* * cmd 压缩与解压缩命令 */ private static String rarCmd = "C:\\Program Files\\WinRAR\\Rar.exe a "; private static String unrarCmd = "C:\\Program Files\\WinRAR\\UnRar x "; public static void main(String[] args) throws Exception { RARFile("RARRemote", "E:\\RemoteXml.xml", "E:\\"); } /** * 将1个文件压缩成RAR格式 * rarName 压缩后的压缩文件名(不包含后缀) * fileName 需要压缩的文件名(必须包含路径) * destDir 压缩后的压缩文件存放路径 */ public static void RARFile(String rarName, String fileName, String destDir) { rarCmd += destDir + rarName + ".rar " + fileName; try { Runtime rt = Runtime.getRuntime(); Process p = rt.exec(rarCmd); if (p.waitFor() == 0) { System.out.println("压缩成功"); } } catch (Exception e) { System.out.println(e.getMessage()); } } /** * 将1个RAR文件解压 * rarFileName 需要解压的RAR文件(必须包含路径信息以及后缀) * destDir 解压后的文件放置目录 */ public static void unRARFile(String rarFileName, String destDir) { unrarCmd += rarFileName + " " + destDir; try { Runtime rt = Runtime.getRuntime(); Process p = rt.exec(unrarCmd); if (p.waitFor() == 0) { System.out.println("解压成功"); } } catch (Exception e) { System.out.println(e.getMessage()); } } } |
|||
MD5 加密处理 | MD5 加密处理 | ||
package com.tiancom.pas.util; import java.security.MessageDigest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class CopyOfMD5Digest { protected static Log log = LogFactory.getLog(CopyOfMD5Digest.class); // private static MessageDigest __md5 = getInstance(); // public static MessageDigest getInstance() { MessageDigest ret = null; try { ret = MessageDigest.getInstance("MD5"); } catch (Exception e) { } return ret; } // public static String digest(String s) { StringBuffer __digestBuffer = new StringBuffer(); __digestBuffer.setLength(0); if(null != s){ byte abyte0[] = __md5.digest(s.getBytes()); for (int i = 0; i < abyte0.length; i++){ __digestBuffer.append(toHex(abyte0[i])); } return __digestBuffer.toString(); }else{ return null; } } // public static String toHex(byte one) { String HEX = "0123456789ABCDEF"; char[] result = new char[2]; result[0] = HEX.charAt((one & 0xf0) >> 4); result[1] = HEX.charAt(one & 0x0f); String mm = new String(result); return mm; } // /** * @param args */ public static void main(String[] args) { System.out.println(digest("111111")); } } |
|||
Java 根据汉字得到拼音2 | Java 根据汉字得到拼音 | ||
import java.io.UnsupportedEncodingException; public class ChineseCharToEn { private final static int[] li_SecPosValue = { 1601, 1637, 1833, 2078, 2274, 2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858, 4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590 }; private final static String[] lc_FirstLetter = { "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "w", "x", "y", "z" }; /** */ /** * 取得给定汉字串的首字母串,即声母串 * * @param str 给定汉字串 * @return 声母串 */ public String getAllFirstLetter(String str) { if (str == null || str.trim().length() == 0) { return ""; } String _str = ""; for (int i = 0; i < str.length(); i++) { _str = _str + this.getFirstLetter(str.substring(i, i + 1)); } return _str; } /** */ /** * 取得给定汉字的首字母,即声母 * * @param chinese 给定的汉字 * @return 给定汉字的声母 */ public String getFirstLetter(String chinese) { if (chinese == null || chinese.trim().length() == 0) { return ""; } chinese = this.conversionStr(chinese, "GBK", "ISO8859-1"); if (chinese.length() > 1) //判断是不是汉字 { int li_SectorCode = (int) chinese.charAt(0); //汉字区码 int li_PositionCode = (int) chinese.charAt(1); //汉字位码 li_SectorCode = li_SectorCode - 160; li_PositionCode = li_PositionCode - 160; int li_SecPosCode = li_SectorCode * 100 + li_PositionCode; //汉字区位码 if (li_SecPosCode > 1600 && li_SecPosCode < 5590) { for (int i = 0; i < 23; i++) { if (li_SecPosCode >= li_SecPosValue[i] && li_SecPosCode < li_SecPosValue[i + 1]) { chinese = lc_FirstLetter[i]; break; } } } else //非汉字字符,如图形符号或ASCII码 { chinese = this.conversionStr(chinese, "ISO8859-1", "GBK"); chinese = chinese.substring(0, 1); } } return chinese; } /** */ /** * 字符串编码转换 * * @param str 要转换编码的字符串 * @param charsetName 原来的编码 * @param toCharsetName 转换后的编码 * @return 经过编码转换后的字符串 */ private String conversionStr(String str, String charsetName, String toCharsetName) { try { str = new String(str.getBytes(charsetName), toCharsetName); } catch (UnsupportedEncodingException ex) { System.out.println("字符串编码转换异常:" + ex.getMessage()); } return str; } public static void main(String[] args) { ChineseCharToEn cte = new ChineseCharToEn(); System.out.println("'天维数码'的首个拼音字母是:" + cte.getFirstLetter("天维数码")); } } |
|||
Java 实现zip加压解压 | Java 实现zip加压解压 | ||
package com.common; import java.io.*; import java.util.*; import java.util.zip.*; public class ZipFiles_20091120 { static final int BUFFER = 2048; //压缩缓冲区大小 public int files = 0; public String filename = ""; /** * 对选定的当前目录下所有文件进行压缩 * @param inputUrl 被压缩文件所在目录路径,路径要已"/"结束 * @param outputUrl 压缩文件输出路径,包括zip文件名称 */ public void zip(String inputUrl, String outputUrl) { try { BufferedInputStream origin = null; FileOutputStream dest = new FileOutputStream(outputUrl); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); byte data[] = new byte[BUFFER]; // 得到当前目录下文件列表 File f = new File(inputUrl); File files[] = f.listFiles(); //compressFiles(inputUrl, files, out, data); /////////// for (int i=0; i < files.length; i++) { if (files[i].isFile()&&!files[i].getName().equals("temp.zip")) { System.out.println("NAME: "+files[i].getName()); System.out.println("Adding: "+files[i]); FileInputStream fi = new FileInputStream(files[i]); origin = new BufferedInputStream(fi, BUFFER); ZipEntry entry = new ZipEntry(files[i].getName()); out.putNextEntry(entry); int count; while((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } origin.close(); } } /////////// out.close(); } catch (Exception e) { e.printStackTrace(); } } /** * 对选定的压缩文件进行解压缩。 * @param inputUrl zip压缩文件路径,包括zip文件名称 * @param outputUrl 解压缩文件输出目录路径 */ public void unZip(String inputUrl, String outputUrl) { try { BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile(inputUrl); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); is = new BufferedInputStream (zipfile.getInputStream(entry)); int count; byte data[] = new byte[BUFFER]; FileOutputStream fos = new FileOutputStream(outputUrl + entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ( (count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } this.files++; dest.flush(); dest.close(); is.close(); } zipfile.close(); } catch (Exception e) { e.printStackTrace(); } } /** * 遍历要压缩的目录及所有子目录 * @param inputUrl * @param files * @param out * @param data */ public void compressFiles(String inputUrl, File[] files, ZipOutputStream out, byte data[]) { try { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { String dirPath = inputUrl + files[i].getName() + "/"; File df = new File(dirPath); File dirFiles[] = df.listFiles(); compressFiles(dirPath, dirFiles, out, data); } else { doZip(inputUrl, files[i], out, data); } } } catch (Exception e) { System.out.println(e); } } /** * 打包压缩文件 * @param inputUrl * @param files * @param out * @param data */ public void doZip(String inputUrl, File files, ZipOutputStream out, byte data[]) { try { FileInputStream fi = new FileInputStream(inputUrl + files.getName()); BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); ZipEntry entry = new ZipEntry(files.getName()); out.putNextEntry(entry); int count; while ( (count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } fi.close(); origin.close(); } catch (IOException e) { System.out.println(e); } } public int getFiles() { return this.files; } static public void main(String args[]) { try { ZipFiles_20091120 zf = new ZipFiles_20091120(); // zf.zip("g:/test/", "g:\\test\\temp.zip"); /* String tempFile="g:\\test\\temp.zip"; File file = new File(tempFile); System.out.println((int) file.length()); byte[] buffer = new byte[ (int) file.length()]; BufferedInputStream input = new BufferedInputStream(new FileInputStream(tempFile)); input.read(buffer, 0, buffer.length); input.close(); long b = System.currentTimeMillis(); System.out.println(buffer); com.sti.datacenter.server.DataControlService ds = new com.sti.datacenter.server.DataControlService(); ds.sendClientData(buffer); */ zf.unZip("D:/temp/zipmobile.zip","D:/temp/"); System.out.println("OOOOOOOOOKKKKKKKKKK"); } catch (Exception e) { } } } |
|||
Java 根据汉字得到拼音1 | Java 根据汉字得到拼音 | ||
import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Set; public class GB2Alpha { private static LinkedHashMap spellMap = null; static { if (spellMap == null) { spellMap = new LinkedHashMap(400); } initialize(); } private static void spellPut(String spell, int ascii) { spellMap.put(spell, new Integer(ascii)); } private static void initialize() { spellPut("a", -20319); spellPut("ai", -20317); spellPut("an", -20304); spellPut("ang", -20295); spellPut("ao", -20292); spellPut("ba", -20283); spellPut("bai", -20265); spellPut("ban", -20257); spellPut("bang", -20242); spellPut("bao", -20230); spellPut("bei", -20051); spellPut("ben", -20036); spellPut("beng", -20032); spellPut("bi", -20026); spellPut("bian", -20002); spellPut("biao", -19990); spellPut("bie", -19986); spellPut("bin", -19982); spellPut("bing", -19976); spellPut("bo", -19805); spellPut("bu", -19784); spellPut("ca", -19775); spellPut("cai", -19774); spellPut("can", -19763); spellPut("cang", -19756); spellPut("cao", -19751); spellPut("ce", -19746); spellPut("ceng", -19741); spellPut("cha", -19739); spellPut("chai", -19728); spellPut("chan", -19725); spellPut("chang", -19715); spellPut("chao", -19540); spellPut("che", -19531); spellPut("chen", -19525); spellPut("cheng", -19515); spellPut("chi", -19500); spellPut("chong", -19484); spellPut("chou", -19479); spellPut("chu", -19467); spellPut("chuai", -19289); spellPut("chuan", -19288); spellPut("chuang", -19281); spellPut("chui", -19275); spellPut("chun", -19270); spellPut("chuo", -19263); spellPut("ci", -19261); spellPut("cong", -19249); spellPut("cou", -19243); spellPut("cu", -19242); spellPut("cuan", -19238); spellPut("cui", -19235); spellPut("cun", -19227); spellPut("cuo", -19224); spellPut("da", -19218); spellPut("dai", -19212); spellPut("dan", -19038); spellPut("dang", -19023); spellPut("dao", -19018); spellPut("de", -19006); spellPut("deng", -19003); spellPut("di", -18996); spellPut("dian", -18977); spellPut("diao", -18961); spellPut("die", -18952); spellPut("ding", -18783); spellPut("diu", -18774); spellPut("dong", -18773); spellPut("dou", -18763); spellPut("du", -18756); spellPut("duan", -18741); spellPut("dui", -18735); spellPut("dun", -18731); spellPut("duo", -18722); spellPut("e", -18710); spellPut("en", -18697); spellPut("er", -18696); spellPut("fa", -18526); spellPut("fan", -18518); spellPut("fang", -18501); spellPut("fei", -18490); spellPut("fen", -18478); spellPut("feng", -18463); spellPut("fo", -18448); spellPut("fou", -18447); spellPut("fu", -18446); spellPut("ga", -18239); spellPut("gai", -18237); spellPut("gan", -18231); spellPut("gang", -18220); spellPut("gao", -18211); spellPut("ge", -18201); spellPut("gei", -18184); spellPut("gen", -18183); spellPut("geng", -18181); spellPut("gong", -18012); spellPut("gou", -17997); spellPut("gu", -17988); spellPut("gua", -17970); spellPut("guai", -17964); spellPut("guan", -17961); spellPut("guang", -17950); spellPut("gui", -17947); spellPut("gun", -17931); spellPut("guo", -17928); spellPut("ha", -17922); spellPut("hai", -17759); spellPut("han", -17752); spellPut("hang", -17733); spellPut("hao", -17730); spellPut("he", -17721); spellPut("hei", -17703); spellPut("hen", -17701); spellPut("heng", -17697); spellPut("hong", -17692); spellPut("hou", -17683); spellPut("hu", -17676); spellPut("hua", -17496); spellPut("huai", -17487); spellPut("huan", -17482); spellPut("huang", -17468); spellPut("hui", -17454); spellPut("hun", -17433); spellPut("huo", -17427); spellPut("ji", -17417); spellPut("jia", -17202); spellPut("jian", -17185); spellPut("jiang", -16983); spellPut("jiao", -16970); spellPut("jie", -16942); spellPut("jin", -16915); spellPut("jing", -16733); spellPut("jiong", -16708); spellPut("jiu", -16706); spellPut("ju", -16689); spellPut("juan", -16664); spellPut("jue", -16657); spellPut("jun", -16647); spellPut("ka", -16474); spellPut("kai", -16470); spellPut("kan", -16465); spellPut("kang", -16459); spellPut("kao", -16452); spellPut("ke", -16448); spellPut("ken", -16433); spellPut("keng", -16429); spellPut("kong", -16427); spellPut("kou", -16423); spellPut("ku", -16419); spellPut("kua", -16412); spellPut("kuai", -16407); spellPut("kuan", -16403); spellPut("kuang", -16401); spellPut("kui", -16393); spellPut("kun", -16220); spellPut("kuo", -16216); spellPut("la", -16212); spellPut("lai", -16205); spellPut("lan", -16202); spellPut("lang", -16187); spellPut("lao", -16180); spellPut("le", -16171); spellPut("lei", -16169); spellPut("leng", -16158); spellPut("li", -16155); spellPut("lia", -15959); spellPut("lian", -15958); spellPut("liang", -15944); spellPut("liao", -15933); spellPut("lie", -15920); spellPut("lin", -15915); spellPut("ling", -15903); spellPut("liu", -15889); spellPut("long", -15878); spellPut("lou", -15707); spellPut("lu", -15701); spellPut("lv", -15681); spellPut("luan", -15667); spellPut("lue", -15661); spellPut("lun", -15659); spellPut("luo", -15652); spellPut("ma", -15640); spellPut("mai", -15631); spellPut("man", -15625); spellPut("mang", -15454); spellPut("mao", -15448); spellPut("me", -15436); spellPut("mei", -15435); spellPut("men", -15419); spellPut("meng", -15416); spellPut("mi", -15408); spellPut("mian", -15394); spellPut("miao", -15385); spellPut("mie", -15377); spellPut("min", -15375); spellPut("ming", -15369); spellPut("miu", -15363); spellPut("mo", -15362); spellPut("mou", -15183); spellPut("mu", -15180); spellPut("na", -15165); spellPut("nai", -15158); spellPut("nan", -15153); spellPut("nang", -15150); spellPut("nao", -15149); spellPut("ne", -15144); spellPut("nei", -15143); spellPut("nen", -15141); spellPut("neng", -15140); spellPut("ni", -15139); spellPut("nian", -15128); spellPut("niang", -15121); spellPut("niao", -15119); spellPut("nie", -15117); spellPut("nin", -15110); spellPut("ning", -15109); spellPut("niu", -14941); spellPut("nong", -14937); spellPut("nu", -14933); spellPut("nv", -14930); spellPut("nuan", -14929); spellPut("nue", -14928); spellPut("nuo", -14926); spellPut("o", -14922); spellPut("ou", -14921); spellPut("pa", -14914); spellPut("pai", -14908); spellPut("pan", -14902); spellPut("pang", -14894); spellPut("pao", -14889); spellPut("pei", -14882); spellPut("pen", -14873); spellPut("peng", -14871); spellPut("pi", -14857); spellPut("pian", -14678); spellPut("piao", -14674); spellPut("pie", -14670); spellPut("pin", -14668); spellPut("ping", -14663); spellPut("po", -14654); spellPut("pu", -14645); spellPut("qi", -14630); spellPut("qia", -14594); spellPut("qian", -14429); spellPut("qiang", -14407); spellPut("qiao", -14399); spellPut("qie", -14384); spellPut("qin", -14379); spellPut("qing", -14368); spellPut("qiong", -14355); spellPut("qiu", -14353); spellPut("qu", -14345); spellPut("quan", -14170); spellPut("que", -14159); spellPut("qun", -14151); spellPut("ran", -14149); spellPut("rang", -14145); spellPut("rao", -14140); spellPut("re", -14137); spellPut("ren", -14135); spellPut("reng", -14125); spellPut("ri", -14123); spellPut("rong", -14122); spellPut("rou", -14112); spellPut("ru", -14109); spellPut("ruan", -14099); spellPut("rui", -14097); spellPut("run", -14094); spellPut("ruo", -14092); spellPut("sa", -14090); spellPut("sai", -14087); spellPut("san", -14083); spellPut("sang", -13917); spellPut("sao", -13914); spellPut("se", -13910); spellPut("sen", -13907); spellPut("seng", -13906); spellPut("sha", -13905); spellPut("shai", -13896); spellPut("shan", -13894); spellPut("shang", -13878); spellPut("shao", -13870); spellPut("she", -13859); spellPut("shen", -13847); spellPut("sheng", -13831); spellPut("shi", -13658); spellPut("shou", -13611); spellPut("shu", -13601); spellPut("shua", -13406); spellPut("shuai", -13404); spellPut("shuan", -13400); spellPut("shuang", -13398); spellPut("shui", -13395); spellPut("shun", -13391); spellPut("shuo", -13387); spellPut("si", -13383); spellPut("song", -13367); spellPut("sou", -13359); spellPut("su", -13356); spellPut("suan", -13343); spellPut("sui", -13340); spellPut("sun", -13329); spellPut("suo", -13326); spellPut("ta", -13318); spellPut("tai", -13147); spellPut("tan", -13138); spellPut("tang", -13120); spellPut("tao", -13107); spellPut("te", -13096); spellPut("teng", -13095); spellPut("ti", -13091); spellPut("tian", -13076); spellPut("tiao", -13068); spellPut("tie", -13063); spellPut("ting", -13060); spellPut("tong", -12888); spellPut("tou", -12875); spellPut("tu", -12871); spellPut("tuan", -12860); spellPut("tui", -12858); spellPut("tun", -12852); spellPut("tuo", -12849); spellPut("wa", -12838); spellPut("wai", -12831); spellPut("wan", -12829); spellPut("wang", -12812); spellPut("wei", -12802); spellPut("wen", -12607); spellPut("weng", -12597); spellPut("wo", -12594); spellPut("wu", -12585); spellPut("xi", -12556); spellPut("xia", -12359); spellPut("xian", -12346); spellPut("xiang", -12320); spellPut("xiao", -12300); spellPut("xie", -12120); spellPut("xin", -12099); spellPut("xing", -12089); spellPut("xiong", -12074); spellPut("xiu", -12067); spellPut("xu", -12058); spellPut("xuan", -12039); spellPut("xue", -11867); spellPut("xun", -11861); spellPut("ya", -11847); spellPut("yan", -11831); spellPut("yang", -11798); spellPut("yao", -11781); spellPut("ye", -11604); spellPut("yi", -11589); spellPut("yin", -11536); spellPut("ying", -11358); spellPut("yo", -11340); spellPut("yong", -11339); spellPut("you", -11324); spellPut("yu", -11303); spellPut("yuan", -11097); spellPut("yue", -11077); spellPut("yun", -11067); spellPut("za", -11055); spellPut("zai", -11052); spellPut("zan", -11045); spellPut("zang", -11041); spellPut("zao", -11038); spellPut("ze", -11024); spellPut("zei", -11020); spellPut("zen", -11019); spellPut("zeng", -11018); spellPut("zha", -11014); spellPut("zhai", -10838); spellPut("zhan", -10832); spellPut("zhang", -10815); spellPut("zhao", -10800); spellPut("zhe", -10790); spellPut("zhen", -10780); spellPut("zheng", -10764); spellPut("zhi", -10587); spellPut("zhong", -10544); spellPut("zhou", -10533); spellPut("zhu", -10519); spellPut("zhua", -10331); spellPut("zhuai", -10329); spellPut("zhuan", -10328); spellPut("zhuang", -10322); spellPut("zhui", -10315); spellPut("zhun", -10309); spellPut("zhuo", -10307); spellPut("zi", -10296); spellPut("zong", -10281); spellPut("zou", -10274); spellPut("zu", -10270); spellPut("zuan", -10262); spellPut("zui", -10260); spellPut("zun", -10256); spellPut("zuo", -10254); } /** * 获得单个汉字的Ascii. * * @param cn * char 汉字字符 * @return int 错误返回 0,否则返回ascii */ private static int getCnAscii(char cn) { byte[] bytes = (String.valueOf(cn)).getBytes(); if (bytes == null || bytes.length > 2 || bytes.length <= 0) { // 错误 return 0; } if (bytes.length == 1) { // 英文字符 return bytes[0]; } if (bytes.length == 2) { // 中文字符 int hightByte = 256 + bytes[0]; int lowByte = 256 + bytes[1]; int ascii = (256 * hightByte + lowByte) - 256 * 256; return ascii; } return 0; // 错误 } /** * 根据ASCII码到SpellMap中查找对应的拼音 * * @param ascii * int 字符对应的ASCII * @return String 拼音,首先判断ASCII是否>0&<160,如果是返回对应的字符, * 否则到SpellMap中查找,如果没有找到拼音,则返回null,如果找到则返回拼音. */ private static String getSpellByAscii(int ascii) { if (ascii > 0 && ascii < 160) { // 单字符--英文或半角字符 return String.valueOf((char) ascii); } if (ascii < -20319 || ascii > -10247) { // 不知道的字符 return null; } Set keySet = spellMap.keySet(); Iterator it = keySet.iterator(); String spell0 = null; String spell = null; int asciiRang0 = -20319; int asciiRang; while (it.hasNext()) { spell = (String) it.next(); Object valObj = spellMap.get(spell); if (valObj instanceof Integer) { asciiRang = ((Integer) valObj).intValue(); if (ascii >= asciiRang0 && ascii < asciiRang) { // 区间找到 return (spell0 == null) ? spell : spell0; } else { spell0 = spell; asciiRang0 = asciiRang; } } } return null; } /** * 检验字符传是否正确 * * @param cnStr * @return */ private static boolean validate(String cnStr) { if (cnStr == null || cnStr.trim().equals("")) { return false; } else { return true; } } /** * 返回字符串的全拼,是汉字转化为全拼,其它字符不进行转换 * * @param cnStr * String 字符串 * @return String 转换成全拼后的字符串 */ public static String getFullSpell(String cnStr) { if (!validate(cnStr)) { return cnStr; } char[] chars = cnStr.toCharArray(); StringBuffer retuBuf = new StringBuffer(); for (int i = 0, Len = chars.length; i < Len; i++) { int ascii = getCnAscii(chars[i]);// 得到单个中文的Ascii码 if (ascii == 0) { // 取ascii时出错 retuBuf.append(chars[i]); } else { String spell = getSpellByAscii(ascii); if (spell == null) { retuBuf.append(chars[i]); } else { retuBuf.append(spell); } // end of if spell == null } // end of if ascii <= -20400 } // end of for return retuBuf.toString(); } /** * 返回字符串拼音的首字母,是汉字转化为拼音,其它字符不进行转换 * * @param cnStr * String 字符串 * @return String 转换成拼音后的字符串(全大写) */ public static String getFirstSpell(String cnStr) { if (!validate(cnStr)) { return cnStr; } char[] chars = cnStr.toCharArray(); StringBuffer retuBuf = new StringBuffer(); for (int i = 0, Len = chars.length; i < Len; i++) { int ascii = getCnAscii(chars[i]);// 得到单个中文的Ascii码 if (ascii == 0) { // 取ascii时出错 retuBuf.append(chars[i]); } else { String spell = getSpellByAscii(ascii); if (spell == null) { retuBuf.append(chars[i]); } else { retuBuf.append(spell.substring(0, 1)); } // end of if spell == null } // end of if ascii <= -20400 } // end of for return retuBuf.toString().toUpperCase(); } } |
|||
java连接数据库大全 | java连接数据库大全 | java连接数据库大全 | |
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.ResultSet; import java.sql.Statement; import java.sql.*; public class BaseConnection { private Connection con = null; protected Connection getCon(){ ResultSet rs=null; Statement stmt = null; try { Class.forName("org.gjt.mm.mysql.Driver"); String url="jdbc:mysql://192.168.0.10/数据库名?user=USR&password=PWD"; conn = DriverManager.getConnection(url); stmt = conn.createStatement(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return con; } } 1、Oracle8/8i/9i数据库(thin模式) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID String user="test"; String password="test"; Connection conn= DriverManager.getConnection(url,user,password); 2、DB2数据库 Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance(); String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名 String user="admin"; String password=""; Connection conn= DriverManager.getConnection(url,user,password); 3、Sql Server7.0/2000数据库 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; //mydb为数据库 String user="sa"; String password=""; Connection conn= DriverManager.getConnection(url,user,password); 4、Sybase数据库 Class.forName("com.sybase.jdbc.SybDriver").newInstance(); String url =" jdbc:sybase:Tds:localhost:5007/myDB"; //myDB为你的数据库名 Properties sysProps = System.getProperties(); SysProps.put("user","userid"); SysProps.put("password","user_password"); Connection conn= DriverManager.getConnection(url, SysProps); 5、Informix数据库 Class.forName("com.informix.jdbc.IfxDriver").newInstance(); String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver; user=testuser;password=testpassword"; //myDB为数据库名 Connection conn= DriverManager.getConnection(url); 6、MySQL数据库 Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" //myDB为数据库名 Connection conn= DriverManager.getConnection(url); 7、PostgreSQL数据库 Class.forName("org.postgresql.Driver").newInstance(); String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名 String user="myuser"; String password="mypassword"; Connection conn= DriverManager.getConnection(url,user,password); //还有下面一些,内含有驱动包下载地址 1. MySQL(http://www.mysql.com)mm.mysql-2.0.2-bin.jar Class.forName( "org.gjt.mm.mysql.Driver" ); cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd ); 2. PostgreSQL(http://www.de.postgresql.org)pgjdbc2.jar Class.forName( "org.postgresql.Driver" ); cn = DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName", sUsr, sPwd ); 3. Oracle(http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip Class.forName( "oracle.jdbc.driver.OracleDriver" ); cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd ); 4. Sybase(http://jtds.sourceforge.net)jconn2.jar Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" ); cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd ); //(Default-Username/Password: "dba"/"sql") 5. Microsoft SQLServer(http://jtds.sourceforge.net) Class.forName( "net.sourceforge.jtds.jdbc.Driver" ); cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd ); 6. Microsoft SQLServer(http://www.microsoft.com) Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ); cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd ); 7. ODBC Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd ); 8.DB2(新添加) Class.forName("com.ibm.db2.jdbc.net.DB2Driver"); String url="jdbc:db2://192.9.200.108:6789/SAMPLE" cn = DriverManager.getConnection( url, sUsr, sPwd ); 补充 Microsoft SQL Server series (6.5, 7.x and 2000) and Sybase 10 JDBC Name: jTDS URL: http://jtds.sourceforge.net/ Version: 0.5.1 Download URL: http://sourceforge.net/project/showfiles.php?group_id=33291 语法: Class.forName("net.sourceforge.jtds.jdbc.Driver "); Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password"); or Connection con = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password"); Postgresql JDBC Name: PostgreSQL JDBC URL: http://jdbc.postgresql.org/ Version: 7.3.3 build 110 Download URL: http://jdbc.postgresql.org/download.html 语法: Class.forName("org.postgresql.Driver"); Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password"); IBM AS400主机在用的JDBC语法 有装V4R4以上版本的Client Access Express 可以在C:\Program Files\IBM\Client Access\jt400\lib 找到 driver 档案 jt400.zip,并更改扩展名成为 jt400.jar 语法 java.sql.DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ()); Class.forName("com.ibm.as400.access.AS400JDBCConnection"); con = DriverManager.getConnection("jdbc:as400://IP","user","password"); informix Class.forName("com.informix.jdbc.IfxDriver").newInstance(); String url = "jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver; user=testuser;password=testpassword"; Lib:jdbcdrv.zip<br><br>Class.forName( "com.sybase.jdbc.SybDriver" )<br>url="jdbc:sybase:Tds:127.0.0.1:2638/asademo";<br>SybConnection connection= (SybConnection)DriverManager.getConnection(url,"dba","sql");<br> 补充两个 SAP DB Class.forName ("com.sap.dbtech.jdbc.DriverSapDB"); java.sql.Connection connection = java.sql.DriverManager.getConnection ( "jdbc:sapdb://" + host + "/" + database_name,user_name, password) InterBase String url = "jdbc:interbase://localhost/e:/testbed/database/employee.gdb"; Class.forName("interbase.interclient.Driver"); //Driver d = new interbase.interclient.Driver (); /* this will also work if you do not want the line above */ Connection conn = DriverManager.getConnection( url, "sysdba", "masterkey" ); 我也来补一个吧:HSqlDB url: http://hsqldb.sourceforge.net/ driver: org.hsqldb.jdbcDriver 连接方式有4种,分别为: con-str(内存): jdbc:hsqldb. con-str(本地): jdbc:hsqldb:/path/to/the/db/dir con-str(http): jdbc:hsqldb:http://dbsrv con-str(hsql): jdbc:hsqldb:hsql://dbsrv |