隨筆-71  評論-5  文章-0  trackbacks-0
            2015年3月17日
               摘要: 一個stmt多個rs進行操作.那么從stmt得到的rs1,必須馬上操作此rs1后,才能去得到另外的rs2,再對rs2操作.不能互相交替使用,會引起rs已經關閉錯誤——Operation not allowed after ResultSet closed.錯誤的代碼如下: stmt=conn.createStatement();  rs=stm...  閱讀全文
          posted @ 2015-10-13 14:58 藤本薔薇 閱讀(216) | 評論 (0)編輯 收藏
          在 JDK1.5 引入自動裝箱和拆箱的機制后,包裝類和基本類型之間的轉換就更加輕松便利了。

          裝箱:把基本類型轉換成包裝類,使其具有對象的性質,又可分為手動裝箱和自動裝箱

          int i= 10; //定義一個int基本類型值
          Integer x = new Integer(i); //手動裝箱
          Integer y = i; //自動裝箱
          posted @ 2015-09-22 20:28 藤本薔薇 閱讀(229) | 評論 (0)編輯 收藏

          功能:將一個由英文字母組成的字符串轉換成指定格式---從右邊開始每三個字母用逗號分隔的形式。

          請在編輯器中的第 4、10 行將代碼填寫完整

          運行效果: j,aew,kjl,dfx,mop,zdmpublic static void main(String[] args) {
                  // Java文件名
          String fileName = "HelloWorld.jav"; 
                  // 郵箱
          String email = "laurenyang@imooc.com";
          // 判斷.java文件名是否正確:合法的文件名應該以.java結尾
                  /*
                  參考步驟:
                  1、獲取文件名中最后一次出現"."號的位置
                  2、根據"."號的位置,獲取文件的后綴
                  3、判斷"."號位置及文件后綴名
                  */
                  //獲取文件名中最后一次出現"."號的位置
          int index = fileName.lastIndexOf('.');
                  
                  // 獲取文件的后綴
          String prefix = fileName.substring(index);
                  
          // 判斷必須包含"."號,且不能出現在首位,同時后綴名為"java"
          if (index !=0 && index != -1 &&  prefix.equals("java")) {
          System.out.println("Java文件名正確");
          } else {
          System.out.println("Java文件名無效");
          }

                  // 判斷郵箱格式是否正確:合法的郵箱名中至少要包含"@", 并且"@"是在"."之前
                   /*
                  參考步驟:
                  1、獲取文件名中"@"符號的位置
                  2、獲取郵箱中"."號的位置
                  3、判斷必須包含"@"符號,且"@"必須在"."之前
                  */
             // 獲取郵箱中"@"符號的位置
          int index2 = email.indexOf("@");
                  
                  // 獲取郵箱中"."號的位置
          int index3 = email.indexOf('.');
                  
          // 判斷必須包含"@"符號,且"@"必須在"."之前
          if (index2 != -1 && index3 > index2) {
          System.out.println("郵箱格式正確");
          } else {
          System.out.println("郵箱格式無效");
          }
          }






          字節是計算機存儲信息的基本單位,1 個字節等于 8 位, gbk 編碼中 1 個漢字字符存儲需要 2 個字節1 個英文字符存儲需要 1 個字節。所以我們看到上面的程序運行結果中,每個漢字對應兩個字節值,如“學”對應 “-47 -89” ,而英文字母 “J” 對應 “74” 。同時,我們還發現漢字對應的字節值為負數,原因在于每個字節是 8 位,最大值不能超過 127,而漢字轉換為字節后超過 127,如果超過就會溢出,以負數的形式顯示。






               public static void main(String[] args) {
          // 定義一個字符串
          String s = "aljlkdsflkjsadjfklhasdkjlflkajdflwoiudsafhaasdasd";
                  
                  // 出現次數
          int num = 0;
                   // 循環遍歷每個字符,判斷是否是字符 a ,如果是,累加次數
          for ( int i=0;i<s.length()-1;i++)
          {
                      // 獲取每個字符,判斷是否是字符a
          if (  'a'==s.charAt(i)      ) {
                          // 累加統計次數
          num++; 
          }
          }
          System.out.println("字符a出現的次數:" + num);
          }




          功能:將一個由英文字母組成的字符串轉換成指定格式---從右邊開始每三個字母用逗號分隔的形式。

          請在編輯器中的第 4、10 行將代碼填寫完整

          運行效果: j,aew,kjl,dfx,mop,zdm


              public static void main(String[] args) {
          // 創建一個空的StringBuilder對象
                  StringBuilder str = new StringBuilder();
          // 追加字符串
          str.append("jaewkjldfxmopzdm");
                  // 從后往前每隔三位插入逗號
          for(int i = str.length()-3; i>0 ; i=i-3){
               
                     str.insert(i,",");
          }
              
                  // 將StringBuilder對象轉換為String對象并輸出
          System.out.print(str.toString());
          }

           結果: j,aew,kjl,dfx,mop,zdm
          posted @ 2015-09-22 16:12 藤本薔薇 閱讀(357) | 評論 (0)編輯 收藏
          String s1 = "imooc";
          String s2 = "imooc";
                  
                  //定義字符串s3,保存“I love”和s1拼接后的內容
          String s3 = "I love" + s1; 
                  // 比較字符串s1和s2
          // imooc為常量字符串,多次出現時會被編譯器優化,只創建一個對象
          System.out.println("s1和s2內存地址相同嗎?" + (s1 == s2));
                  
                  //比較字符串s1和s3
          System.out.println("s1和s3內存地址相同嗎?" +  (s1==s3));
          String s4 = "I love " + s1;
                   //比較字符串s4和s3
          // s1是變量,s4在運行時才知道具體值,所以s3和s4是不同的對象
          System.out.println("s3和s4內存地址相同嗎?" + (s4 == s3));
          posted @ 2015-09-22 15:26 藤本薔薇 閱讀(277) | 評論 (0)編輯 收藏
          //外部類HelloWorld
          public class HelloWorld {
              
              // 內部類Inner,類Inner在類HelloWorld的內部
              public class Inner {
                  
          // 內部類的方法
          public void show() {
          System.out.println("welcome to imooc!");
          }
          }
              
          public static void main(String[] args) {
                  
                  // 創建外部類對象
          HelloWorld hello = new HelloWorld();
                  // 創建內部類對象
          Inner i = hello.new Inner();
                  // 調用內部類對象的方法
          i.show();
          }
          }
          posted @ 2015-09-09 15:47 藤本薔薇 閱讀(313) | 評論 (0)編輯 收藏














          posted @ 2015-09-09 14:41 藤本薔薇 閱讀(321) | 評論 (0)編輯 收藏
          不清楚路徑的查找 : find / -name mysql


           MYSQL常用經典命令(沒有試過)
          1.停止mysql
          kill -9 `ps -ef | grep mysqld_safe| grep -v grep| awk '{print $2}'`
          kill -9 `ps -ef | grep 'mysqld' | grep -v grep| awk '{print $2}'`

          2.啟動mysql
          cd /usr/local/mysql-5.4.1-beta-linux-x86_64-glibc23
          /bin/sh bin/mysqld_safe --user=mysql & 


          find /home/lijiajia/ -amin -10        #查找在系統中最后10分鐘訪問的文件
          find /home/lijiajia/ -atime -2        #查找在系統中最后48小時訪問的文件
          find /home/lijiajia/ -empty           #查找在系統中為空的文件或者文件夾
          find /home/lijiajia/ -mmin -5         # 查找在系統中最后5 分鐘里修改過的文件
          find /home/lijiajia/ -mtime -1        #查找在系統中最后24 小時里修改過的文件
          find /home/lijiajia/ -nouser          #查找在系統中屬于作廢用戶的文件(不明白是什么意思)
          find /home/lijiajia/ -amin 10         #查找在系統中最后10分鐘訪問的文件
          find /home/ftp/pub -user lijiajia     #查找在系統中屬于lijiajia這個用戶的文件
          posted @ 2015-09-02 10:26 藤本薔薇 閱讀(214) | 評論 (0)編輯 收藏
            public static Map ConvertObjToMap(Object obj){
                        Map<String,Object> reMap = new HashMap<String,Object>();
                        if (obj == null
                         return null;
                        Field[] fields = obj.getClass().getDeclaredFields();
                        try {
                         for(int i=0;i<fields.length;i++){
                          try {
                           Field f = obj.getClass().getDeclaredField(fields[i].getName());
                           f.setAccessible(true);
                                 Object o = f.get(obj);
                                 if(o == null){
                                     o = "";
                                 }else{
                                     o = String.valueOf(o);
                                 }
                                 reMap.put(fields[i].getName(), String.valueOf(o));
                          } catch (NoSuchFieldException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                          } catch (IllegalArgumentException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                          } catch (IllegalAccessException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                          }
                         }
                        } catch (SecurityException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                        } 
                        return reMap;
                       }
          posted @ 2015-08-31 19:52 藤本薔薇 閱讀(1018) | 評論 (0)編輯 收藏

          import java.io.IOException;
          import java.util.Date;

          import org.apache.commons.httpclient.HttpClient;
          import org.apache.commons.httpclient.HttpException;
          import org.apache.commons.httpclient.NameValuePair;
          import org.apache.commons.httpclient.methods.PostMethod;
          import org.dom4j.Document;
          import org.dom4j.DocumentException;
          import org.dom4j.DocumentHelper;
          import org.dom4j.Element;

          import com.alibaba.fastjson.JSONObject;
          import com.huoniu.openapi.constant.Constant.MESSAGE;
          import com.huoniu.openapi.constant.InvokeContext;
          import com.huoniu.openapi.model.RetCode;
          import com.huoniu.openapi.model.RetMsg;
          import com.huoniu.openapi.model.SmsCode;
          import com.huoniu.openapi.service.SmsCodeService;
          import com.huoniu.openapi.utils.AESUtil;
          import com.huoniu.openapi.utils.SmsUtil;
          import com.huoniu.openapi.web.interceptor.InvokeContextInitInterceptor;
          import com.puff.framework.annotation.Before;
          import com.puff.framework.annotation.Controller;
          import com.puff.framework.annotation.Inject;
          import com.puff.framework.annotation.InterceptorChain;
          import com.puff.framework.utils.JsonUtil;
          import com.puff.framework.utils.StringUtil;
          import com.puff.web.view.TextView;
          import com.puff.web.view.View;
          import com.puff.web.view.ViewFactory;

          @Controller("/rest/sms")
          public class HuyiSmsController {    

              private static String content = "您的驗證碼是:%s。請不要把驗證碼泄露給其他人。";
              public View send(){
                  
                  String invokeData = InvokeContext.getInvokeData();
                  if (StringUtil.blank(invokeData)) {
                      return json(RetMsg.error(RetCode.OTHER_ERROR, "發送短信失敗!"));
                  }
                  
                  JSONObject jsonObject = JSONObject.parseObject(invokeData);
                  String  mobile = jsonObject.getString("customer_no");
                  if (StringUtil.blank(mobile)) {
                      return json(RetMsg.error(RetCode.NULL_PARAM, "手機號碼不能為空"));
                  }
                      
                      HttpClient client = new HttpClient(); 
                      PostMethod method = new PostMethod(MESSAGE.NEW_MESSAGEURL);  //接口地址
                          
                      client.getParams().setContentCharset("UTF-8");
                      method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

                      int mobile_code = (int)((Math.random()*9+1)*100000);        
                                                         System.out.println("mobile_code : "+mobile_code);
                      NameValuePair[] data = {//提交短信
                              new NameValuePair("account", MESSAGE.NEW_ACCOUNT), 
                              new NameValuePair("password", SmsUtil.MD5Encode(MESSAGE.NEW_PASSWORD)),
                              new NameValuePair("mobile", mobile), 
                              new NameValuePair("content", String.format(content, mobile_code)),
                      };
                      
                      method.setRequestBody(data);        

                      try {
                          client.executeMethod(method);    
                          String SubmitResult =method.getResponseBodyAsString();
                          Document doc = DocumentHelper.parseText(SubmitResult); 
                          Element root = doc.getRootElement();
                          String code = root.elementText("code");    
                          String msg = root.elementText("msg");    
                          String smsid = root.elementText("smsid");    
                                      
                          if(code == "2"){  //發送成功,寫庫
                              
                          }
                          
                      } catch (HttpException e) {
                          e.printStackTrace();
                      } catch (IOException e) {
                          e.printStackTrace();
                      } catch (DocumentException e) {
                          e.printStackTrace();
                      }    
                      
                  
                      return json(RetMsg.success("發送成功!!!"));
                  
              }
              
              
              
              public View json(RetMsg msg) {
                  String data = JsonUtil.toJson(msg);
                  if (InvokeContext.isEncrypt()) {
                      data = AESUtil.encrypt(data);
                  }
                  return ViewFactory.text(data, TextView.ContentType.JSON);
              }

          }
          posted @ 2015-08-31 10:02 藤本薔薇 閱讀(306) | 評論 (0)編輯 收藏
          import org.apache.commons.httpclient.HttpClient;
          import org.apache.commons.httpclient.NameValuePair;
          import org.apache.commons.httpclient.methods.PostMethod;

          import com.alibaba.fastjson.JSONObject;
          import com.huoniu.openapi.constant.Constant.TONGLIAN;


          public class TLInterfaceService {
              
              private static final String USERNAME = "";
              private static final String PASSWORD = "";
              private static final String TENANT = "";
              private static final String GRANT_TYPE_GET = "password";    
              private static final String GRANT_TYPE_REFRESH = "refresh_token";    
              
              private static String TOKEN = null;
              private static String REFRESH_TOKEN = null;
              private static long EXPIRES_IN ;
              private static long START_DATE;

              
              public  String getToken() {
                  if(TOKEN==null){
                          TOKEN  = login();
                  }else{
                      Date date = new Date();
                      if(START_DATE-date.getTime()<EXPIRES_IN-30){
                          TOKEN  = refresh();
                      }
                      
                  }
                  
                  return TOKEN;
              }
              
              
              public  void setToken(String token) {
                  TOKEN = token;
              }


              /**
               * 登陸,獲取token
               * 
          @return 
               
          */
                      
                  public static String login(){

                          HttpClient httpClient = new HttpClient();
                          String URL = String.format(TONGLIAN.PREV_PATH, "");  //接口地址
                          try {
                              PostMethod postMethod = new PostMethod(URL);
                              postMethod.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
                              NameValuePair[] data = { 
                                      new NameValuePair("username", USERNAME),
                                      new NameValuePair("password", PASSWORD),
                                      new NameValuePair("tenant",  TENANT),
                                      new NameValuePair("grant_type", GRANT_TYPE_GET)
                                       };
                              postMethod.setRequestBody(data);
                              int statusCode = httpClient.executeMethod(postMethod);
                              if(200 == statusCode){
                                  String body  = postMethod.getResponseBodyAsString();
                                  JSONObject json=JSONObject.parseObject(body);
                                  TOKEN = json.getString("access_token");
                                  REFRESH_TOKEN = json.getString("refresh_token");
                                  EXPIRES_IN = Long.parseLong(json.getString("expires_in"));
                                  START_DATE =  (new Date()).getTime();
                              }
                          } catch (Exception e) {
                              
                          }
                          return TOKEN;
                   }
                  
                  /**
                   * refresh_token
                   * 
          @return 
                   
          */
                                  
                  public static String refresh(){
                          
                      HttpClient httpClient = new HttpClient();
                          String URL = String.format(TONGLIAN.PREV_PATH, ""); //接口地址
                          try {
                              PostMethod postMethod = new PostMethod(URL);
                              postMethod.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
                              NameValuePair[] data = { 
                                      new NameValuePair("refresh_token", REFRESH_TOKEN),
                                      new NameValuePair("grant_type", GRANT_TYPE_REFRESH)
                               };
                              postMethod.setRequestBody(data);
                              int statusCode = httpClient.executeMethod(postMethod);
                              
                              if(200 == statusCode){
                                  String body  = postMethod.getResponseBodyAsString();
                                  JSONObject json=JSONObject.parseObject(body);
                                  TOKEN = json.getString("access_token");
                                  REFRESH_TOKEN = json.getString("refresh_token");
                                  EXPIRES_IN = Long.parseLong(json.getString("expires_in"));
                                  START_DATE =  (new Date()).getTime();
                              }
                          } catch (Exception e) {
                              
                          }
                          return TOKEN;
                   }

          }
          posted @ 2015-08-31 09:54 藤本薔薇 閱讀(290) | 評論 (0)編輯 收藏

          /Files/kokosang/html5拖拽上傳.zip

            前幾天想做個給安卓app升級做個上傳頁面,然后從網上down了個頁面下面(主要是嫌棄自己頁面整的太丑,見不了人),然后就一直在整后臺取值的辦法
            各種百度,值取出來了,但是,悲催的是總是亂碼,崩潰了,大神看了后,鄙視一番,給我整了下,簡直就是重寫了

            貼出來,先放張頁面效果
            


            賞心悅目的后臺來咯

          import java.io.BufferedWriter;
          import java.io.File;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.OutputStream;
          import java.io.OutputStreamWriter;
          import java.util.List;

          import org.apache.log4j.Logger;
          import org.apache.tomcat.util.http.fileupload.FileItem;
          import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
          import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;

          import com.puff.framework.annotation.Controller;
          import com.puff.web.mvc.PuffContext;
          import com.puff.web.view.View;

          @Controller("/upload/android")
          public class AndroidVersionUploadController {

              private static final Logger logger = Logger.getLogger(UserImageController.class);
              
              private static final String FILE_PATH = "C:/Users/Administrator/Desktop";
              
              private static final String FILE_APK_NAME = "/nn.apk";
              private static final String FILE_VER_NAME = "/ver.txt";
              
              /**
               * 版本上傳
               * 
          @return
               * 
          @throws Exception 
               
          */
              public View update() throws Exception {
                  DiskFileItemFactory factory = new DiskFileItemFactory(); 
                  ServletFileUpload upload = new ServletFileUpload(factory); 
                  List<FileItem> items = upload.parseRequest( PuffContext.getRequest()); 
                  
                  String ver = null;
                  String info = null;
                  String isFoucs = null;
                  for(Object object : items) { 
                      FileItem fileItem = (FileItem)object; 
                      if(fileItem.isFormField()) { 
                          
                          String name = fileItem.getFieldName();
                          String value = fileItem.getString("utf-8");
                          
                          if("ver".equals(name)){
                              ver = value;
                          }else if("content".equals(name)){
                              info = value;
                          }else if("radio".equals(name)){
                              isFoucs = value;
                          }
                      } else {
                          saveFileInfo(fileItem);
                      }
                  } 
                  
                  saveContentInfo(ver, info, isFoucs);
                  
                  return null;
              
              }

              private void saveFileInfo(FileItem fileItem) {
                  
                  InputStream is = null;
                  OutputStream os = null;
                  try {
                      File file = new File(FILE_PATH);
                      if(file.exists()) {
                          file.mkdirs();
                      }
                      
                      is = fileItem.getInputStream();
                      os = new FileOutputStream(FILE_PATH + FILE_APK_NAME);
                      
                      int len = 0;
                      byte[] buffer = new byte[8 * 1024];
                      while ((len = is.read(buffer, 0, 8 * 1024)) != -1) {
                          os.write(buffer, 0, len);
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                  } finally {
                      closeOutputStream(os);
                      closeInputStream(is);
                  }
              }
              
              public void saveContentInfo(String ver, String info, String isFoucs) {
                  BufferedWriter br = null;
                  try {
                      File file = new File(FILE_PATH);
                      if(file.exists()) {
                          file.mkdirs();
                      }
                      
                      br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FILE_PATH + FILE_VER_NAME), "utf-8"));
                      br.write("ver:" + ver + "\r\n");   //版本號
                      br.write("update:" + isFoucs+ "\r\n");   //是否強制更新
                      br.write("content:" + info );    //版本升級內容
                      br.flush();
                  } catch (Exception e) {
                      e.printStackTrace();
                  } finally {
                      try {
                          if(br != null) {
                              br.close();
                          }
                      } catch (IOException e) {
                          e.printStackTrace();
                      } finally {
                          br = null;
                      }
                  }
              }


              private void closeOutputStream(OutputStream os) {
                  if(os != null) {
                      try {
                          os.close();
                      } catch (IOException e) {
                          e.printStackTrace();
                      } finally {
                          os = null;
                      }
                  }
              }
              
              private void closeInputStream(InputStream is) {
                  if(is != null) {
                      try {
                          is.close();
                      } catch (IOException e) {
                          e.printStackTrace();
                      } finally {
                          is = null;
                      }
                  }
              }
          }
          posted @ 2015-08-24 10:35 藤本薔薇 閱讀(262) | 評論 (0)編輯 收藏
          public static void main(String[] args) {

                  String xml = "<?xml version=\"1.0\" encoding=\"gb2312\"?><p><seqid></seqid><code></code><msg>成功</msg>" +
                                    "<node><ename>huoniu</ename><cname>火牛</cname><prefix>108</prefix><begin>20150603</begin><end>20160630</end><borr>1000000</borr><margin>100000</margin><usdborr>1000000</usdborr><usdmargin>100000</usdmargin><mainp>0.60</mainp><midp>0.60</midp><growp>0.60</growp><mainpt>0.60</mainpt><midpt>0.60</midpt><growpt>0.30</growpt><shcomm>0.000300</shcomm><szcomm>0.000300</szcomm><warn>1.000</warn><close>1.000</close><interest>200</interest><commf>13</commf><layout>p-huo01:1100000:574810</layout><unmoney>0</unmoney><tstatus>0</tstatus><cstatus>0</cstatus></node>" +
                                    " <node><ename>nn</ename><cname>牛牛</cname><prefix>102</prefix><begin>20150615</begin><end>20151015</end><borr>10000000</borr><margin>8000000</margin><usdborr>10000000</usdborr><usdmargin>8000000</usdmargin><mainp>0.60</mainp><midp>0.60</midp><growp>0.30</growp><mainpt>0.60</mainpt><midpt>0.60</midpt><growpt>0.30</growpt><shcomm>0.003000</shcomm><szcomm>0.003000</szcomm><warn>0.800</warn><close>0.800</close><interest>0</interest><commf>0</commf><layout></layout><unmoney>18000000</unmoney><tstatus>0</tstatus><cstatus>0</cstatus></node>" +
                                   "<node><ename>ag-huo</ename><cname>兜底代理商</cname><prefix>huo</prefix><begin>20150602</begin><end>20160630</end><borr>0</borr><margin>0</margin><usdborr>0</usdborr><usdmargin>0</usdmargin><mainp>0.60</mainp><midp>0.60</midp><growp>0.30</growp><mainpt>0.60</mainpt><midpt>0.60</midpt><growpt>0.30</growpt><shcomm>0.000300</shcomm><szcomm>0.000300</szcomm><warn>0.010</warn><close>0.010</close><interest>0</interest><commf>0</commf><layout></layout><unmoney>0</unmoney><tstatus>0</tstatus><cstatus>0</cstatus></node></p>";

                  List<Map> nodeList = new ArrayList<Map>();
                  Map<String, Object> sendMap = new HashMap<String, Object>();
                  try {
                      
                      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                      DocumentBuilder db = dbf.newDocumentBuilder();
                      Document doc = db.parse(new InputSource(new StringReader(xml)));
                      Element root = doc.getDocumentElement();// 根節點

                      Node node = root.getFirstChild();
                      while(node != null) {
                          String nodeName = node.getNodeName().trim();
                          String nodeValue = node.getTextContent().trim();
                          
                          if("node".equals(nodeName) && node.hasChildNodes()) {
                              
                              Map<String, Object> nodeMap = new HashMap<String, Object>();
                              
                              Node childNode = node.getFirstChild();
                              while(childNode != null) {
                                  nodeMap.put(childNode.getNodeName(), childNode.getTextContent());
                                  childNode = childNode.getNextSibling();
                              }
                              
                              nodeList.add(nodeMap);
                          } else {
                              sendMap.put(nodeName, nodeValue);
                          }
                          
                          node = node.getNextSibling();
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  
                  sendMap.put("node", nodeList);
                  
                  System.out.println(sendMap);
              }



          打印結果 :
          {node=[{warn=1.000, cstatus=0, tstatus=0, borr=1000000, growpt=0.30, unmoney=0, midpt=0.60, usdmargin=100000, commf=13, close=1.000, begin=20150603, shcomm=0.000300, usdborr=1000000, growp=0.60, interest=200, layout=p-huo01:1100000:574810, prefix=108, ename=huoniu, midp=0.60, mainpt=0.60, margin=100000, szcomm=0.000300, cname=火牛, end=20160630, mainp=0.60}, 
                      {warn=0.800, cstatus=0, tstatus=0, borr=10000000, growpt=0.30, unmoney=18000000, midpt=0.60, usdmargin=8000000, commf=0, close=0.800, begin=20150615, shcomm=0.003000, usdborr=10000000, growp=0.30, interest=0, layout=, ename=nn, midp=0.60, mainpt=0.60, margin=8000000, szcomm=0.003000, end=20151015, mainp=0.60},
                      {warn=0.010, cstatus=0, tstatus=0, borr=0, growpt=0.30, unmoney=0, midpt=0.60, usdmargin=0, commf=0, close=0.010, begin=20150602, shcomm=0.000300, usdborr=0, growp=0.30, interest=0, layout=, prefix=huo, ename=ag-huo, midp=0.60, mainpt=0.60, margin=0, szcomm=0.000300, end=20160630, mainp=0.60}], seqid=, code=, msg=成功}
          posted @ 2015-08-09 10:15 藤本薔薇 閱讀(267) | 評論 (0)編輯 收藏
                public static void main(String[] args) throws Exception {
                      Map<String, Object> sendMap = new HashMap<String, Object>();
                      String data = "<?xml version=\"1.0\" encoding=\"gb2312\"?><p><seqid></seqid><client>0BF3F2D9A01797BBF05D6BC89877DC91</client><ename>108-wc</ename><code>0</code><msg>成功</msg><totalm>12447.97</totalm><cash>5669.13</cash><stockm>6778.84</stockm><num>2</num><stock><node><market>0</market><symbol>600104</symbol><direct>1</direct><type>0</type><avgprice>21.010</avgprice><holdnum>299</holdnum></node><node><market>0</market><symbol>601818</symbol><direct>1</direct><type>0</type><avgprice>4.993</avgprice><holdnum>4</holdnum></node></stock></p>";

                      List<Map> nodeList = new ArrayList<Map>();
                      try {
                          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                          DocumentBuilder db = dbf.newDocumentBuilder();
                          Document doc = db.parse(new InputSource(new StringReader(data)));
                          Element root = doc.getDocumentElement();// 根節點
                          Node node = root.getFirstChild();
                          while(node != null) {
                              String nodeName = node.getNodeName().trim();
                              String nodeValue = node.getTextContent().trim();
                              if("stock".equals(nodeName) && node.hasChildNodes()) {
                                  Node  nodeOne =  node.getFirstChild();
                                  while(nodeOne != null) {
                                   String nodeOneName = nodeOne.getNodeName().trim();
                                   if("node".equals(nodeOneName) && nodeOne.hasChildNodes()){
                                       Map<String, Object> nodeMap = new HashMap<String, Object>();
                                        Node threeNode = nodeOne.getFirstChild();
                                          while(threeNode != null) {
                                              nodeMap.put(threeNode.getNodeName(), threeNode.getTextContent());
                                              threeNode = threeNode.getNextSibling();
                                          }
                                          nodeList.add(nodeMap);
                                        }
                                     nodeOne = nodeOne.getNextSibling();
                                     }
                                  }else{
                                      sendMap.put(nodeName, nodeValue);
                                  }
                              node = node.getNextSibling();
                              }                    
                          sendMap.put("node", nodeList);
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                      System.out.println(sendMap);
                }  


          打印結果:{node=[{direct=1, market=0, symbol=600104, avgprice=21.010, holdnum=299, type=0},
                       {direct=1, market=0, symbol=601818, avgprice=4.993, holdnum=4, type=0}],
                        num=2, seqid=, client=0BF3F2D9A01797BBF05D6BC89877DC91, stockm=6778.84, cash=5669.13, ename=108-wc, code=0, totalm=12447.97, msg=成功}
          posted @ 2015-08-09 10:09 藤本薔薇 閱讀(477) | 評論 (0)編輯 收藏
          /Files/kokosang/DoubleUtil.txt



          package frameWork.util;
          import java.math.BigDecimal;
          import java.text.DecimalFormat;
          /**   
           * 由于Java的簡單類型不能夠精確的對浮點數進行運算,這個工具類提供精   
           * 確的浮點數運算,包括加減乘除和四舍五入。   
           */    
          public class DoubleUtil {
          //這個類不能實例化    
          private DoubleUtil(){    
          }  
          //默認除法運算精度    
          private static final int DEF_DIV_SCALE = 10;  
          //默認的保留位數
          private static DecimalFormat df=new DecimalFormat("0.00");  
          /**
          * 按照格式保留幾位
          * @param money  double數
          * @param format 格式
          * @return
          */
          public static double  format(double money,String format){
          if(format != null && format != ""){
          df=new DecimalFormat(format); 
          }
          double moneyformat=new Double(df.format(money).toString());  
          return moneyformat;
          }
          /**   
          * 提供精確的加法運算。   
          * @param v1 被加數   
          * @param v2 加數   
          * @return 兩個參數的和   
          */    
          public static double add(double v1,double v2){    
          BigDecimal b1 = new BigDecimal(Double.toString(v1));    
          BigDecimal b2 = new BigDecimal(Double.toString(v2));    
          return b1.add(b2).doubleValue();    
          }    
          /**   
          * 提供精確的減法運算。   
          * @param v1 被減數   
          * @param v2 減數   
          * @return 兩個參數的差   
          */    
          public static double sub(double v1,double v2){    
          BigDecimal b1 = new BigDecimal(Double.toString(v1));    
          BigDecimal b2 = new BigDecimal(Double.toString(v2));    
          return b1.subtract(b2).doubleValue();    
          }    
          /**   
          * 提供精確的乘法運算。   
          * @param v1 被乘數   
          * @param v2 乘數   
          * @return 兩個參數的積   
          */    
          public static double mul(double v1,double v2){    
          BigDecimal b1 = new BigDecimal(Double.toString(v1));    
          BigDecimal b2 = new BigDecimal(Double.toString(v2));    
          return b1.multiply(b2).doubleValue();    
          }    
          /**   
          * 提供(相對)精確的除法運算,當發生除不盡的情況時,精確到   
          * 小數點以后10位,以后的數字四舍五入。   
          * @param v1 被除數   
          * @param v2 除數   
          * @return 兩個參數的商   
          */    
          public static double div(double v1,double v2){    
          return div(v1,v2,DEF_DIV_SCALE);    
          }    
          /**   
          * 提供(相對)精確的除法運算。當發生除不盡的情況時,由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();    
          }    
          /**   
          * 提供精確的小數位四舍五入處理。   
          * @param v 需要四舍五入的數字   
          * @param scale 小數點后保留幾位   
          * @return 四舍五入后的結果   
          */    
          public static double round(double v,int scale){    
          if(scale<0){    
          throw new IllegalArgumentException("The scale must be a positive integer or zero");    
          }    
          BigDecimal b = new BigDecimal(Double.toString(v));    
          BigDecimal one = new BigDecimal("1");    
          return b.divide(one,scale,BigDecimal.ROUND_HALF_UP).doubleValue();    
          }    
          /**   
          * 提供精確的類型轉換(Float)   
          * @param v 需要被轉換的數字   
          * @return 返回轉換結果   
          */    
          public static float convertsToFloat(double v){    
          BigDecimal b = new BigDecimal(v);    
          return b.floatValue();    
          }    
          /**   
          * 提供精確的類型轉換(Int)不進行四舍五入   
          * @param v 需要被轉換的數字   
          * @return 返回轉換結果   
          */    
          public static int convertsToInt(double v){    
          BigDecimal b = new BigDecimal(v);    
          return b.intValue();    
          }    
          /**   
          * 提供精確的類型轉換(Long)   
          * @param v 需要被轉換的數字   
          * @return 返回轉換結果   
          */    
          public static long convertsToLong(double v){    
          BigDecimal b = new BigDecimal(v);    
          return b.longValue();    
          }    
          /**   
          * 返回兩個數中大的一個值   
          * @param v1 需要被對比的第一個數   
          * @param v2 需要被對比的第二個數   
          * @return 返回兩個數中大的一個值   
          */    
          public static double returnMax(double v1,double v2){    
          BigDecimal b1 = new BigDecimal(v1);    
          BigDecimal b2 = new BigDecimal(v2);    
          return b1.max(b2).doubleValue();    
          }    
          /**   
          * 返回兩個數中小的一個值   
          * @param v1 需要被對比的第一個數   
          * @param v2 需要被對比的第二個數   
          * @return 返回兩個數中小的一個值   
          */    
          public static double returnMin(double v1,double v2){    
          BigDecimal b1 = new BigDecimal(v1);    
          BigDecimal b2 = new BigDecimal(v2);    
          return b1.min(b2).doubleValue();    
          }    
          /**   
          * 精確對比兩個數字   
          * @param v1 需要被對比的第一個數   
          * @param v2 需要被對比的第二個數   
          * @return 如果兩個數一樣則返回0,如果第一個數比第二個數大則返回1,反之返回-1   
          */    
          public static int compareTo(double v1,double v2){    
          BigDecimal b1 = new BigDecimal(v1);    
          BigDecimal b2 = new BigDecimal(v2);    
          return b1.compareTo(b2);    
          }
          /**
          * 格式化double
          * @param arg0
          * @param num
          * @return
          */
          public static String doubleFormat(double arg0,Integer num){
          DecimalFormat df = new DecimalFormat("####.00"); 
          /*DecimalFormat df2 = new DecimalFormat("##.00%");  
          DecimalFormat df3 = new DecimalFormat("###,##0.00");*/
          if(num !=null){
          if(num == 1){
          df = new DecimalFormat("####.0"); 
          }else if(num == 2){
          df = new DecimalFormat("####.00"); 
          }else if(num == 3){
          df = new DecimalFormat("####.000"); 
          }else if(num == 4){
          df = new DecimalFormat("####.0000"); 
          }
          }else{
          df = new DecimalFormat("####"); 
          }
          if(df.format(arg0).contains(".")){
          if(df.format(arg0).substring(0, df.format(arg0).indexOf(".")).length()<=0){
          df = new DecimalFormat("0.00");
          if(num !=null){
          if(num == 1){
          df = new DecimalFormat("0.0"); 
          }else if(num == 2){
          df = new DecimalFormat("0.00"); 
          }else if(num == 3){
          df = new DecimalFormat("0.000"); 
          }else if(num == 4){
          df = new DecimalFormat("0.0000"); 
          }
          }else{
          df = new DecimalFormat("0"); 
          }
          }
          }
          return df.format(arg0);
          }
          /**
          * 百分比格式化
          * @param arg0
          * @param num
          * @return
          */
          public static String percentageFormat(double arg0,Integer num){
          DecimalFormat df = new DecimalFormat("##.00%");
          if(num !=null){
          if(num == 1){
          df = new DecimalFormat("####.0%"); 
          }else if(num == 2){
          df = new DecimalFormat("####.00%"); 
          }else if(num == 3){
          df = new DecimalFormat("####.000%"); 
          }else if(num == 4){
          df = new DecimalFormat("####.0000%"); 
          }
          }else{
          df = new DecimalFormat("####%"); 
          }
          if(df.format(arg0).contains(".")){
          if(df.format(arg0).substring(0, df.format(arg0).indexOf(".")).length()<=0){
          df = new DecimalFormat("0.00%");
          if(num !=null){
          if(num == 1){
          df = new DecimalFormat("0.0%"); 
          }else if(num == 2){
          df = new DecimalFormat("0.00%"); 
          }else if(num == 3){
          df = new DecimalFormat("0.000%"); 
          }else if(num == 4){
          df = new DecimalFormat("0.0000%"); 
          }
          }else{
          df = new DecimalFormat("0%"); 
          }
          }
          }
          return df.format(arg0);
          }
          /**
          * double每三位短號分割
          * @param arg0
          * @param num
          * @return
          */
          public static String splitNumberFormat(double arg0,Integer num){
          DecimalFormat df = new DecimalFormat("###,##0.00");
          if(num !=null){
          if(num == 1){
          df = new DecimalFormat("###,##0.0"); 
          }else if(num == 2){
          df = new DecimalFormat("###,##0.00"); 
          }else if(num == 3){
          df = new DecimalFormat("###,##0.000"); 
          }else if(num == 4){
          df = new DecimalFormat("###,##0.0000"); 
          }
          }else{
          df = new DecimalFormat("###,###"); 
          }
          return df.format(arg0);
          }
          }
          posted @ 2015-08-07 13:47 藤本薔薇 閱讀(587) | 評論 (0)編輯 收藏
          假如  redis  在/usr/local/bin

          配置文件在/usr/local/redis-2.8.21 

           root@iZ239bujfzrZ:    /usr/local/bin# ./redis-server redis.conf nohup 
          posted @ 2015-08-07 10:36 藤本薔薇 閱讀(214) | 評論 (0)編輯 收藏

                public static interface NUMBER{
          public static String STR_FORMAT = "00000"; 
                  static String TOKEN = null; 
          }


          //配資單號格式
              public static String AddOne(String code){
             Integer intHao = Integer.parseInt(code);
             intHao++;
             DecimalFormat df = new DecimalFormat(NUMBER.STR_FORMAT);
             return df.format(intHao);
              }
              
              public static void main(String[] args) {
              String code = "ASD0034252345234500001";
                 String  xlh = code.substring(code.length()-5, code.length());
                 System.out.println("數據庫原有的最大序列號:"+xlh);
                 if(xlh!=null){
                System.out.println("累加的新生成的序列號:"+AddOne(xlh));
                 }else{
                System.out.println("最新的新生成的序列號:"+"00001"); //如果沒有手動生成一條最小的
                 }
            }
              
          posted @ 2015-08-03 11:50 藤本薔薇 閱讀(452) | 評論 (0)編輯 收藏
              /**
               * 獲取股票板塊信息
               * 滬市A股 : 600、601、603 開頭
               * 深市A股 : 000開頭
               * 中小板 : 002開頭
               * 創業板 : 300開頭
               * 滬市新股申購:730
               * @param code
               * @return
               */
              public static int getPlateInfo(String code){
              if(code.startsWith("600") || code.startsWith("601") || code.startsWith("603")){
              return 0;
              }else if(code.startsWith("000")){
              return 1;
              }else if(code.startsWith("002")){
              return 2;
              }else if(code.startsWith("300")){
              return 3;
              }else if(code.startsWith("730")){
              return 4;
              }else {
              return 5;
              }
              }
          posted @ 2015-07-29 19:07 藤本薔薇 閱讀(373) | 評論 (0)編輯 收藏
           
                      我想把String 類型 yyyy-MM-dd 格式的數據轉換成 String 類型  yyyyMMdd 格式,然后

          String end_date = "2015-09-07";
                  SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); 
                  Date date_2 = formatter.parse(end_date);
          String date_22 = formatter.format(date_2);
          System.out.println(date_2);
          System.out.println(date_22);

            
                  打印出來結果是:
                          Tue Dec 09 00:00:00 CST 2014
                          20141209

                 后來,吾家上神告知,不能直接轉
                
                          String end_date = "2015-09-07";
          DateFormat format =new SimpleDateFormat("yyyy-MM-dd");
          Date date_1 = format.parse(end_date);
          format = new SimpleDateFormat("yyyyMMdd");  
          String date_11 = format.format(date_1);
          System.out.println(date_1);
          System.out.println(date_11);


                打印出來結果是:

                         Mon Sep 07 00:00:00 CST 2015
                         20150907


              總結語: 吾家上神棒棒噠!!!

          posted @ 2015-07-27 16:27 藤本薔薇 閱讀(204) | 評論 (0)編輯 收藏
                   
                       原本寫了 if  else  判斷股票所屬板塊的,覺得繁瑣,就去改了下面的

                            public static void main(String[] args) {
              String code ="002348";
              String stock = "002".equals(code.substring(0,3)) ? "002" : code.substring(0,1);
          System.out.println(stock);
          }

                         然后跑去得瑟,被鄙視了,然后  ↓↓↓↓

                           public static String getPlateInfo(String code){
              return code.startsWith("002") ? "002" : code.substring(0,1);
                            }

                      還補了一刀,你看你寫的什么玩意兒,哼,好想讓他跪搓衣板
          posted @ 2015-07-02 00:26 藤本薔薇 閱讀(232) | 評論 (0)編輯 收藏
          Map<String, Object> userInfoMap = new HashMap<String, Object>();
          // String data = JsonUtil.toJson(infoMap);
          userInfoMap.put("agent", agent);
          userInfoMap.put("ename", ename);
          Map<String, Object> infoMap = SocketLogic.logic.userInfo(userInfoMap);
          JSONObject rootObj = (JSONObject)JSONObject.toJSON(infoMap);
          JSONArray nodeArr = rootObj.getJSONArray("node");
          for(int i = 0; i < nodeArr.size(); i ++) {
          authority = nodeArr.getJSONObject(i).get("authority").toString();          //交易權限
          margin = nodeArr.getJSONObject(i).getLongValue("margin");  //保證金
          warn = nodeArr.getJSONObject(i).getFloatValue("warn");      //警戒線
          close = nodeArr.getJSONObject(i).getFloatValue("close");    //平倉線
          end =  nodeArr.getJSONObject(i).getLongValue("end");       //結束時間
          mainp = nodeArr.getJSONObject(i).getFloatValue("mainp"); //主板單票比例
          midp = nodeArr.getJSONObject(i).getFloatValue("midp");   //中小板單票比例
          growp = nodeArr.getJSONObject(i).getFloatValue("growp"); //創業板單票比例
             
          }
          posted @ 2015-06-29 19:20 藤本薔薇 閱讀(336) | 評論 (1)編輯 收藏
          轉自 : http://wzf7065.iteye.com/blog/1567587



          public class StringTest {
              private static int counter = 0;
              public static void main(String[] args) {
              String str1 = "sd& ^^java***java(((java";
              String str2 = "java";
              int i = countStr(str1, str2);
              System.out.println("i---------->" + i);
              }
              /**
               * 判斷str1中包含str2的個數
                * @param str1
               * @param str2
               * @return counter
               */
              public static int countStr(String str1, String str2) {
                  if (str1.indexOf(str2) == -1) {
                 return 0;
                  } else if (str1.indexOf(str2) != -1) {
                 counter++;
                 countStr(str1.substring(str1.indexOf(str2) +
                             str2.length()), str2);
                         return counter;
                  }
                 return 0;
              }
          }
          posted @ 2015-06-23 14:47 藤本薔薇 閱讀(1429) | 評論 (0)編輯 收藏

                   select * from  table order by  id   limit    (intPage - 1) * PageRow    , intPage * PageRow




          去重SQL

          select product_code,count(*) as count from h_product_info group by product_code having count>1; 
          select d_date,count(*) as count from h_oddnum group by d_date having count>1 order by d_date desc; 
          delete from h_oddnum where id in (select min(id) from h_oddnum group by d_date having count(d_date) > 1) 
          create table tmp as select min(id) as col1 from blur_article group by title;
          delete from blur_article where id not in (select col1 from tmp); 
          drop table tmp;
          select min(id) from h_oddnum group by d_date having count(d_date) > 1
          create table tmp as select min(id) as col1 from h_oddnum group by d_date having count(d_date) > 1;
          delete from h_oddnum where id not in (select col1 from tmp); 
          drop table tmp;
          insert into h_oddnum(id,d_date,d_code) values('e1d64c5f536b4b1bbfe9f04511c01f3f','20150422172207','00001');
          posted @ 2015-05-19 17:12 藤本薔薇 閱讀(178) | 評論 (0)編輯 收藏
          posted @ 2015-05-04 10:18 藤本薔薇 閱讀(143) | 評論 (0)編輯 收藏

          只能有四位,且可以是數字和字母的混合


          [A-Za-z0-9]{4}
          posted @ 2015-04-24 11:53 藤本薔薇 閱讀(184) | 評論 (0)編輯 收藏
           double rounded = (b1.multiply(b2).multiply(b3)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

          java 四舍五入保留小數(copy)

           
          // 方式一:
          double f = 3.1516;
          BigDecimal b = new BigDecimal(f);
          double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
           
          // 方式二:
          new java.text.DecimalFormat("#.00").format(3.1415926);
          // #.00 表示兩位小數 #.0000四位小數 以此類推…
           
          // 方式三:
          double d = 3.1415926;
          String result = String.format("%.2f", d);
          // %.2f %. 表示 小數點前任意位數 2 表示兩位小數 格式后的結果為f 表示浮點型。
           
          //方法四:
          Math.round(5.2644555 * 100) * 0.01d;
          //String.format("%0" + 15 + "d", 23) 23不足15為就在前面補0

          posted @ 2015-04-24 11:47 藤本薔薇 閱讀(729) | 評論 (0)編輯 收藏

          在項目當中,對于double類型數據的使用比較頻繁。尤其是處理金錢相關的數據,在使用Double類型的數據時,涉及到精度,顯示,四舍五入等等問題。

          1.  顯示問題,當double 數據 小于 0.0001 大于等于 10000000時,直接轉為String輸出時,會顯示為科學計數法。

             1:  double double1 = 0.00009;
             2:  System.out.println(double1); // 9.0E-5
             3:         
             4:  double double2 = 10000000;
             5:  System.out.println(double2); // 1.0E7

          需要使用DecimalFormat 轉化輸出

             1:  DecimalFormat formate = new DecimalFormat("#.######");
             2:  System.out.println(formate.format(double1)); //0.00009
             3:          
             4:  formate = new DecimalFormat("########.##");
             5:  System.out.println(formate.format(double2));//10000000
           
          這里面會有四舍五入問題:
             1:  double double1 = 0.000096789;
             2:  DecimalFormat formate = new DecimalFormat("#.######");
             3:  System.out.println(formate.format(double1)); //0.000097

          當取小數點后六位時,會在第七位四舍五入。

           

          2. 誤差問題,兩個Double類型的數,進行運算。經常會產生誤差。

             1:  System.out.println(0.05 + 0.01); //0.060000000000000005
             2:  System.out.println(1.0 - 0.42);  //0.5800000000000001
             3:  System.out.println(4.015 * 100); //401.49999999999994
             4:  System.out.println(123.3 / 100); //1.2329999999999999

          看似簡單的計算,結果卻出人意料。解決方法是將Double轉為BigDecimal。調用BigDecimal的 運算。

             1:   double d1 = 0.05;
             2:   double d2 = 0.01;
             3:   BigDecimal b1 = new BigDecimal(Double.toString(d1));
             4:   BigDecimal b2 = new BigDecimal(Double.toString(d2));
             5:   System.out.println(b1.add(b2));  //0.06
           
          需要注意的是,如果new BigDecimal()時使用的是double類型的構造方法。問題依舊是可能存在的,這邊要使用String參數的構造方法。
           
          3. 兩個double比較的問題。將double數的運算結果和0比較。由于精度問題,比如if(1-0.999999999999999999 == 0.0) 這個是成立的。
           
          附上double數的運算:
             1:      /**
             2:       * 兩個Double數相加
             3:       * 
             4:       * @param v1
             5:       * @param v2
             6:       * @return
             7:       */
             8:      public static double doubleAdd(Double v1, Double v2) {
             9:   
            10:          BigDecimal b1 = new BigDecimal(v1.toString());
            11:   
            12:          BigDecimal b2 = new BigDecimal(v2.toString());
            13:   
            14:          return b1.add(b2).doubleValue();
            15:   
            16:      }
            17:   
            18:      /**
            19:       * 兩個Double數相減
            20:       * 
            21:       * @param v1
            22:       * @param v2
            23:       * @return
            24:       */
            25:      public static double doubleSub(Double v1, Double v2) {
            26:   
            27:          BigDecimal b1 = new BigDecimal(v1.toString());
            28:   
            29:          BigDecimal b2 = new BigDecimal(v2.toString());
            30:   
            31:          return b1.subtract(b2).doubleValue();
            32:   
            33:      }
            34:   
            35:      /**
            36:       * 兩個Double數相乘
            37:       * 
            38:       * @param v1
            39:       * @param v2
            40:       * @return
            41:       */
            42:      public static double doubleMul(Double v1, Double v2) {
            43:   
            44:          BigDecimal b1 = new BigDecimal(v1.toString());
            45:   
            46:          BigDecimal b2 = new BigDecimal(v2.toString());
            47:   
            48:          return b1.multiply(b2).doubleValue();
            49:   
            50:      }
            51:   
            52:      /**
            53:       * 兩個Double數相除
            54:       * 
            55:       * @param v1
            56:       * @param v2
            57:       * @return
            58:       */
            59:      public static double doubleDiv(Double v1, Double v2) {
            60:   
            61:          BigDecimal b1 = new BigDecimal(v1.toString());
            62:   
            63:          BigDecimal b2 = new BigDecimal(v2.toString());
            64:   
            65:          return b1.divide(b2, DEF_DIV_SCALE, BigDecimal.ROUND_HALF_UP)
            66:                  .doubleValue();
            67:   
            68:      }
            69:   
            70:      /**
            71:       * 兩個Double數相除,并保留scale位小數
            72:       * 
            73:       * @param v1
            74:       * @param v2
            75:       * @param scale
            76:       * @return
            77:       */
            78:      public static double doubleDiv(Double v1, Double v2, int scale) {
            79:   
            80:          if (scale < 0) {
            81:   
            82:              throw new IllegalArgumentException(
            83:   
            84:              "The scale must be a positive integer or zero");
            85:   
            86:          }
            87:          int DEF_DIV_SCALE = 10;
            88:   
            89:          BigDecimal b1 = new BigDecimal(v1.toString());
            90:   
            91:          BigDecimal b2 = new BigDecimal(v2.toString());
            92:   
            93:          return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
            94:   
            95:      }
          posted @ 2015-04-22 18:11 藤本薔薇 閱讀(179) | 評論 (0)編輯 收藏
          語句對的,但不能執行
          delete from h_oddnum where id in (select min(id) from h_oddnum group by d_date having count(d_date) > 1) 

          只能創建臨時表刪除

          create table tmp as select min(id) as col1 from h_oddnum group by d_date having count(d_date) > 1;
          delete from h_oddnum where id not in (select col1 from tmp); 
          drop table tmp;
          posted @ 2015-04-22 16:50 藤本薔薇 閱讀(140) | 評論 (0)編輯 收藏
              Date date = new Date("2014/1/10 18:20");
                  Date date2 = new Date("2014/1/11 3:5");
                  long temp = date2.getTime() - date.getTime();    //相差毫秒數
                  long hours = temp / 1000 3600;                //相差小時數
                  long temp2 = temp % (1000 3600);
                  long mins = temp2 / 1000 60;                    //相差分鐘數
                  System.out.println("date2 與 date 相差" + hours + "小時"+ mins + "分鐘");
          posted @ 2015-04-16 10:40 藤本薔薇 閱讀(137) | 評論 (0)編輯 收藏
          啟動jmeter時
          invalid or corrupt jarfile ApacheJmeter.jar  
          errorlevel=1

          后來才發現是本地jdk配置版本過低是jdk1.5
          如是將環境變量里面的java_home 里面的F:\Installed---success---go\jdk1.5改為C:\Program Files\Java\jdk1.7.0_45
          運行
          jmeter解壓文件下面bin里面的jmeter.bat 啟動成功










          posted @ 2015-04-14 10:20 藤本薔薇 閱讀(471) | 評論 (0)編輯 收藏
             BigDecimal b1 = new BigDecimal(Double.toString(service_charge*matching_term));
             BigDecimal b2 = new BigDecimal(Double.toString(0.7));
                      BigDecimal b3 = new BigDecimal(Double.toString(0.3));
                
          //利息
          Double interest = b1.multiply(b2).doubleValue();
          posted @ 2015-04-13 14:09 藤本薔薇 閱讀(127) | 評論 (0)編輯 收藏




          錯誤的原因:

               調用第三方支付,出現問題,起先以為是重啟服務器造成的,后來查看源代碼,運行,才發現,第三方回調時被攔截。


          posted @ 2015-03-26 16:36 藤本薔薇 閱讀(174) | 評論 (0)編輯 收藏
          String ids = "as,ad,sdf,qwe,rwer,wfv";
          for(String id:ids.split(",")){
          System.out.println(id);
          }


          結果:
          as
          ad
          sdf
          qwe
          rwer
          wfv
          posted @ 2015-03-18 09:39 藤本薔薇 閱讀(443) | 評論 (2)編輯 收藏



            var arr = [{ name: "john", lang: "js" },{ name: "nailwl", lang: "jquery" },{ name: "吳磊", lang: "ext" }]; 
            $.each( arr, function(index, content)
            { 
             alert( "the man's no. is: " + index + ",and " + content.name + " is learning " + content.lang ); 
            });
          posted @ 2015-03-17 16:18 藤本薔薇 閱讀(209) | 評論 (0)編輯 收藏
          主站蜘蛛池模板: 丹东市| 岳西县| 会泽县| 四平市| 邢台市| 广州市| 天气| 公安县| 西平县| 陆丰市| 西畴县| 屏山县| 遂平县| 灵璧县| 绍兴市| 拜城县| 绵阳市| 阜阳市| 女性| 河源市| 延寿县| 天全县| 湖州市| 天峨县| 饶河县| 海口市| 阿勒泰市| 光山县| 萨嘎县| 克山县| 定远县| 巩义市| 博白县| 喀喇| 杨浦区| 平阴县| 潜江市| 张家港市| 延寿县| 拜城县| 紫阳县|