3089589

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年3月26日

摘要: 当一张表的多个字段没有唯一索引时,想要在sql语句中加上判断达到不插入重复记录的目的,可以使用mysql的dualINSERT INTO book_chapter_del(book_id, chapter_id,status)SELECT 20049198, 1000930, 0FROM dualWHERE not exists (select * from book_chapter_delwhere book_id = 20049198 and chapter_id=1000930) limit 1;select express [from dual]; mysql总是作为返回该表达式值的. 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(241) 评论(0) 推荐(0)

摘要: String a = "abc"; Field f = a.getClass().getDeclaredField("value"); f.setAccessible(true); char[] ch = new char[3]; ch[0]='b'; ch[1]='c'; ch[2]='d'; f.set(a, ch); System.out.println(a);此时打印出来的就是bcd,具体在于这一句代码 f.setAccessible(true);值为 ... 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(416) 评论(0) 推荐(0)

摘要: 关于JDBC支不支持批量操作,网上的答案各有各的说法,经过一翻测试,发现MySQL驱动JDBC确实不支持批量操作,如果需要其支持批量操作,需要在MySQL的连接url中加上rewriteBatchedStatements=true,加上后,无论MySQL是循环插入还是批量插入,均有改善测试环境win7 32位系统 mysql5 JDBC驱动为mysql-connector-java-5.1.16-bin.jar,数据库表user为InnorDBpublic static void test_mysql(){ String url="jdbc:mysql://localho... 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(582) 评论(0) 推荐(0)

摘要: 一张表,里面有 id name state customerid 4个字段,其中status有3个值0 1 2 ,用一条sql查询出此种格式 customerid state-0 state-1 state-2 001 11 212 333 002 15 545 3 sql如下: select customid, count(case status when 0 then status else null end) as status-0, ... 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(162) 评论(0) 推荐(0)

摘要: public static void quickSort(int[] sort, int start, int end) {// 设置关键数据key为要排序数组的第一个元素, // 即第一趟排序后,key右边的数全部比key大,key左边的数全部比key小 int key = sort[start]; // 设置数组左边的索引,往右移动判断比key大的数 int i = start; // 设置数组右边的索引,往左移动判断比key小的数 int j = end; // 如果左边索引比右边索引小,则还有数据没有排序 ... 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(98) 评论(0) 推荐(0)

摘要: ImageInputStream iis = ImageIO.createImageInputStream(new File( "E:/1.jpg")); Iterator iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { System.out.println("null"); }else{ ImageReader reader = (ImageReader) iter.next(); ... 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(1038) 评论(0) 推荐(0)

摘要: $ find . -name "*.xml" -exec cp {} /home/data/sslib/sslib/ \;任务内容:把当前文件夹下的以“xml”为后缀名的所有文件复制到/home/data/sslib/sslib/ 目录下。在使用-exec参数时,必须以“\;”结尾,而且之前要有一个空格,否则,系统会提示“find遗漏-exec参数”,命令将无法执行 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(714) 评论(0) 推荐(0)

摘要: 碰到一个在上传完图片后需要将其转换为多种格式的问题,当然在Java程序里可以解决,但灵活性不高,所以就想到了用Process来调用外部命令linux的一个工具ImageMagick来解决问题。waitFor() 导致当前线程等待,如有必要,一直要等到由该 Process 对象表示的进程已经终止。在调用该方法时,经常会出现线程阻塞,Process需要向主线程汇报运行状态,要注意清空缓存区,即Process的InputStream与ErrorStream Process p = Runtime.getRuntime().exec("cmd /c dir"); BufferedR 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(1060) 评论(0) 推荐(0)

摘要: convert命令格式:-resize widthxheight{%} {@} {!} {} {^}1.默认时,宽度和高度表示要最终需要转换图像的最大尺寸,同时Convert会控制图片的宽和高,保证图片按比例进行缩放。如:convert -resize 600×600 src.jpg dst.jpg转换后的dst.jpg的图片大小(宽度为600,而高度已经按比例调整为450).2.如果需要转换成600×600,而图片无需保持原有比例,可以在宽高后面加上一个感叹号!.如:convert -resize 600×600! src.jpg dst.jpg3. 只指定高度 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(483) 评论(0) 推荐(0)

摘要: public static Object arrayGrow(Object obj,int addlength){ Class c = obj.getClass();if(!c.isArray()){return null; } Class type = c.getComponentType();int length = Array.getLength(obj);int newlength = length+addlength; Object newArray = Array.newInstance(type, newlength); ... 阅读全文
posted @ 2013-03-26 09:24 liangge0218 阅读(160) 评论(0) 推荐(0)