<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 100  文章 - 50  trackbacks - 0
    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    常用鏈接

    留言簿(3)

    隨筆分類(lèi)

    隨筆檔案

    文章分類(lèi)

    文章檔案

    收藏夾

    我收藏的一些文章!

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    /**
         * 將某個(gè)日期以固定格式轉(zhuǎn)化成字符串
         *
         * @param date
         * @return String
         */
        public static String dateToStr(java.util.Date date)
        {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String str = sdf.format(date);
            return str;
        }
    ------------------------------------------------------------------------------------------
     /**
         * 判斷任意一個(gè)整數(shù)是否素?cái)?shù)
         *
         * @param n
         * @return boolean
         */
        public static boolean isPrimes(int n)
        {
            for (int i = 2; i <= Math.sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
    ------------------------------------------------------------------------------------------
    /**
         * 獲得任意一個(gè)整數(shù)的階乘,遞歸
          *
         * @param n
         * @return n!
         */
        public static int factorial(int n)
        {
            if (n == 1)
            {
                return 1;
            }
            return n * factorial(n - 1);
        }
    --------------------------------------------------------------------------------------------
    /**
         * 將指定byte數(shù)組以16進(jìn)制的形式打印到控制臺(tái)
         *
         * @param hint
         *            String
         * @param b
         *            byte[]
         * @return void
         */
        public static void printHexString(String hint, byte[] b)
        {
            System.out.print(hint);
            for (int i = 0; i < b.length; i++)
            {
                String hex = Integer.toHexString(b[i] & 0xFF);
                if (hex.length() == 1)
                {
                    hex = '0' + hex;
                }
                System.out.print(hex.toUpperCase() + " ");
            }
            System.out.println("");
        }

    -----------------------------------------------------------------------------------------
    package net.java2000.tools;

    /**
     * Title:        Java Bean 工具
     * Description:
     * Copyright:    Copyright (c) 2001
     * Company:      JAVA世紀(jì)網(wǎng) http://www.java2000.net
     * @author 趙學(xué)慶
     * @version 1.0
     */
    import java.util.*;
    import java.util.regex.Pattern;

    public class StrTools {
     /**
      * 分割字符串
      *
      * @param str
      *            String 原始字符串
      * @param splitsign
      *            String 分隔符
      * @return String[] 分割后的字符串?dāng)?shù)組
      */
     @SuppressWarnings("unchecked")
     public static String[] split(String str, String splitsign) {
      int index;
      if (str == null || splitsign == null)
       return null;
      ArrayList al = new ArrayList();
      while ((index = str.indexOf(splitsign)) != -1) {
       al.add(str.substring(0, index));
       str = str.substring(index + splitsign.length());
       //System.out.println("str is : " +str);
      }
      al.add(str);
      return (String[]) al.toArray(new String[0]);
     }

     /**
      * 替換字符串
      *
      * @param from
      *            String 原始字符串
      * @param to
      *            String 目標(biāo)字符串
      * @param source
      *            String 母字符串
      * @return String 替換后的字符串
      */
     public static String replace(String from, String to, String source) {
      if (source == null || from == null || to == null)
       return null;
      StringBuffer bf = new StringBuffer("");
      int index = -1;
      while ((index = source.indexOf(from)) != -1) {
       bf.append(source.substring(0, index) + to);
       source = source.substring(index + from.length());
       index = source.indexOf(from);
      }
      bf.append(source);
      return bf.toString();
     }

     /**
      * 替換字符串,能能夠在HTML頁(yè)面上直接顯示(替換雙引號(hào)和小于號(hào))
      *
      * @param str
      *            String 原始字符串
      * @return String 替換后的字符串
      */
     public static String htmlencode(String str) {
      if (str == null) {
       return null;
      }

      return replace("\"", "&quot;", replace("<", "&lt;", str));
     }

     /**
      * 替換字符串,將被編碼的轉(zhuǎn)換成原始碼(替換成雙引號(hào)和小于號(hào))
      *
      * @param str
      *            String
      * @return String
      */
     public static String htmldecode(String str) {
      if (str == null) {
       return null;
      }

      return replace("&quot;", "\"", replace("&lt;", "<", str));
     }

     private static final String _BR = "<br/>";

     /**
      * 在頁(yè)面上直接顯示文本內(nèi)容,替換小于號(hào),空格,回車(chē),TAB
      *
      * @param str
      *            String 原始字符串
      * @return String 替換后的字符串
      */
     public static String htmlshow(String str) {
      if (str == null) {
       return null;
      }

      str = replace("<", "&lt;", str);
      str = replace(" ", "&nbsp;", str);
      str = replace("\r\n", _BR, str);
      str = replace("\n", _BR, str);
      str = replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", str);
      return str;
     }

     /**
      * 返回指定字節(jié)長(zhǎng)度的字符串
      *
      * @param str
      *            String 字符串
      * @param length
      *            int 指定長(zhǎng)度
      * @return String 返回的字符串
      */
     public static String toLength(String str, int length) {
      if (str == null) {
       return null;
      }
      if (length <= 0) {
       return "";
      }
      try {
       if (str.getBytes("GBK").length <= length) {
        return str;
       }
      } catch (Exception ex) {
      }
      StringBuffer buff = new StringBuffer();

      int index = 0;
      char c;
      length -= 3;
      while (length > 0) {
       c = str.charAt(index);
       if (c < 128) {
        length--;
       } else {
        length--;
        length--;
       }
       buff.append(c);
       index++;
      }
      buff.append("...");
      return buff.toString();
     }

     /**
      * 判斷是否為整數(shù)
      *
      * @param str
      *            傳入的字符串
      * @return 是整數(shù)返回true,否則返回false
      */
     public static boolean isInteger(String str) {
      Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
      return pattern.matcher(str).matches();
     }

     /**
      * 判斷是否為浮點(diǎn)數(shù),包括double和float
      *
      * @param str
      *            傳入的字符串
      * @return 是浮點(diǎn)數(shù)返回true,否則返回false
      */
     public static boolean isDouble(String str) {
      Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$");
      return pattern.matcher(str).matches();
     }

     /**
      * 判斷輸入的字符串是否符合Email樣式.
      *
      * @param str
      *            傳入的字符串
      * @return 是Email樣式返回true,否則返回false
      */
     public static boolean isEmail(String str) {
      Pattern pattern = Pattern
        .compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
      return pattern.matcher(str).matches();
     }

     /**
      * 判斷輸入的字符串是否為純漢字
      *
      * @param str
      *            傳入的字符竄
      * @return 如果是純漢字返回true,否則返回false
      */
     public static boolean isChinese(String str) {
      Pattern pattern = Pattern.compile("[\u0391-\uFFE5]+$");
      return pattern.matcher(str).matches();
     }

     /**
      * 是否為空白,包括null和""
      *
      * @param str
      * @return
      */
     public static boolean isBlank(String str) {
      return str == null || str.trim().length() == 0;
     }

     /**
      * 判斷是否為質(zhì)數(shù)
      *
      * @param x
      * @return
      */
     public static boolean isPrime(int x) {
      if (x <= 7) {
       if (x == 2 || x == 3 || x == 5 || x == 7)
        return true;
      }
      int c = 7;
      if (x % 2 == 0)
       return false;
      if (x % 3 == 0)
       return false;
      if (x % 5 == 0)
       return false;
      int end = (int) Math.sqrt(x);
      while (c <= end) {
       if (x % c == 0) {
        return false;
       }
       c += 4;
       if (x % c == 0) {
        return false;
       }
       c += 2;
       if (x % c == 0) {
        return false;
       }
       c += 4;
       if (x % c == 0) {
        return false;
       }
       c += 2;
       if (x % c == 0) {
        return false;
       }
       c += 4;
       if (x % c == 0) {
        return false;
       }
       c += 6;
       if (x % c == 0) {
        return false;
       }
       c += 2;
       if (x % c == 0) {
        return false;
       }
       c += 6;
      }
      return true;
     }

     public static void main(String[] args) {
      String[] numbers = { "12345", "-12345", "123.45", "-123.45", ".12345",
        "-.12345", "a12345", "12345a", "123.a45" };
      for (String str : numbers) {
       System.out
         .println(str + "=" + isInteger(str) + " " + isDouble(str));
      }

      String[] emails = { "1@2.com", "1.2@3.com", "1@3.4.5.com" };
      for (String str : emails) {
       System.out.println(str + "=" + isEmail(str));
      }
      String[] chineses = { "中國(guó)", "1中國(guó)", "中國(guó)1", "1中國(guó)2", "中1國(guó)" };
      for (String str : chineses) {
       System.out.println(str + "=" + isChinese(str));
      }
       String str = "lin@san@fu@2009";
       String[] strArray =split(str,"@");
       for(String s: strArray)
       System.out.println(s);
     }
    }
    -------------------------------------------------------------------------------------------------
    /* * Db.java
    Created on 2007年8月20日, 上午 8:37
    */
    import java.io.*;
    import java.sql.*;
    import java.util.Properties;
    public class Db {
       
    private String driver;
       
    private String url;
       
    private String user;
       
    private String password;
       
    private Connection conn;
       
    private Statement stm;
       
    private ResultSet rs;
       
    public Db(){
           
    this("DBConf.properties");
        }
       
    public Db(String conf) {
            loadProperties(conf);
            setConn();
        }
       
    public Connection getConn(){
           
    return this.conn;
        }
     
    //handle the properties file to get the informations for connection
        private void loadProperties(String conf){
            Properties props
    = new Properties();
           
    try {
                props.load(
    new FileInputStream(conf));
            }
    catch (FileNotFoundException e) {
                e.printStackTrace();
            }
    catch (IOException e) {
                e.printStackTrace();
            }
           
    this.driver = props.getProperty("driver");
           
    this.url = props.getProperty("url");
           
    this.user = props.getProperty("user");
           
    this.password = props.getProperty("password");
        }
       
    //implement the Connection
        private void setConn(){
           
    try {
                Class.forName(driver);
               
    this.conn = DriverManager.getConnection(url,user,password);
            }
    catch(ClassNotFoundException classnotfoundexception) {
                  classnotfoundexception.printStackTrace();
                System.err.println(
    "db: " + classnotfoundexception.getMessage());
            }
    catch(SQLException sqlexception) {
                System.err.println(
    "db.getconn(): " + sqlexception.getMessage());
            }
        }
          
    public void doInsert(String sql) {
           
    try {
                Statement statement
    = conn.createStatement();
               
    int i = stm.executeUpdate(sql);
            }
    catch(SQLException sqlexception) {
                System.err.println(
    "db.executeInset:" + sqlexception.getMessage());
            }
        }
       
    public void doDelete(String sql) {
           
    try {
                stm
    = conn.createStatement();
               
    int i = stm.executeUpdate(sql);
            }
    catch(SQLException sqlexception) {
                System.err.println(
    "db.executeDelete:" + sqlexception.getMessage());
            }
        }
       
    public void doUpdate(String sql) {
           
    try {
                stm
    = conn.createStatement();
               
    int i = stm.executeUpdate(sql);
            }
    catch(SQLException sqlexception) {
                System.err.println(
    "db.executeUpdate:" + sqlexception.getMessage());
            }
        }
       
       
    public ResultSet doSelect(String sql) {
           
    try {
                stm
    = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
                rs
    = stm.executeQuery(sql);
            }
    catch(SQLException sqlexception) {
                System.err.println(
    "db.executeQuery: " + sqlexception.getMessage());
            }
           
    return rs;
        }
       
    public static void main(String[] args){
           
    try{
                Db db
    = new Db();
                Connection conn
    = db.getConn();
               
    if(conn != null && !conn.isClosed()) {
                    System.out.println(
    "連結(jié)成功");
                    ResultSet rs
    = db.doSelect("select * from content");
                   
    while(rs.next()){
                        System.out.println(rs.getString(
    1)+":"+rs.getString(2)+":"+rs.getString(3));
                      }
                    rs.close();
                    conn.close();
                }
            }
    catch(SQLException e) {
                e.printStackTrace();
            }
        } 
    }

    posted on 2010-05-09 21:43 fly 閱讀(192) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): java學(xué)習(xí)
    主站蜘蛛池模板: 亚洲女人影院想要爱| 亚洲欧美在线x视频| 好吊妞788免费视频播放| 国产成人精品亚洲| 亚洲av无码国产精品色午夜字幕 | 国产亚洲自拍一区| 久久国产高潮流白浆免费观看 | 99久久99热精品免费观看国产| 亚洲天堂2016| 亚洲熟妇无码另类久久久| 国产一卡2卡3卡4卡2021免费观看 国产一卡2卡3卡4卡无卡免费视频 | 国产精品亚洲综合网站| 亚洲电影国产一区| 亚洲av午夜成人片精品电影 | 亚洲综合另类小说色区| 免费H网站在线观看的| 一级特黄录像免费播放中文版| 亚洲精品高清国产麻豆专区| 又黄又爽无遮挡免费视频| 永久在线观看www免费视频| 无遮挡a级毛片免费看| 亚洲午夜久久久精品电影院| 国产成人精品日本亚洲专区 | 免费人成视频在线播放| 亚洲制服在线观看| 亚洲精品色午夜无码专区日韩| 成全视频免费高清| 69av免费观看| 免费无码一区二区三区蜜桃| 羞羞的视频在线免费观看| 77777午夜亚洲| 亚洲日本中文字幕区| 亚洲综合另类小说色区色噜噜| 毛片基地免费观看| 99精品视频在线观看免费专区| 一个人免费观看www视频| 亚洲乱色熟女一区二区三区蜜臀| 亚洲色图.com| 亚洲综合国产精品| 亚洲产国偷V产偷V自拍色戒| 久久久久亚洲AV无码专区网站 |