日期:2014-05-16 浏览次数:20446 次
public synchronized List getPetternList(String pattern) throws Exception{ log.info("getPetternList DB="+pattern); String path = MLotteryContext.getInstance().get("pettern.dir"); File pathDir = new File(path); if(!pathDir.exists()) pathDir.mkdirs(); log.info("pathDir = "+pathDir); String petternPath = path+"pattern.db"; File newFile = new File(petternPath); log.info("==========start delete Old Pettern DB=========="); deleteFile(newFile); log.info("==========End delete Old Pettern DB=========="); log.info("======Start =======Write Pettern DB==============="); //------------------------ // if (!newFile.exists()) { // newFile.createNewFile(); // } // log.info("=============setExecutable==============="); // newFile.setExecutable(true); // log.info("=============setReadable================="); // newFile.setReadable(true); // log.info("=============setWritable================="); // newFile.setWritable(true); // InputStream inStream = new FileInputStream(pattern); // FileOutputStream fs = new FileOutputStream(newFile); // byte[] buffer = new byte[1444]; // int bytesum = 0; // int byteread = 0; // while ((byteread = inStream.read(buffer)) != -1) { // bytesum += byteread; // log.info("=============bytesum===="+bytesum); // // System.out.println(bytesum); // fs.write(buffer, 0, byteread); // } // inStream.close(); // log.info("======End =======Write Pettern DB==============="); File oldFile = new File(pattern); boolean bool = oldFile.renameTo(newFile); log.info("Current PetternDB:"+newFile.getPath()+" bool = " + bool); Class.forName("org.sqlite.JDBC"); log.info("DB="+petternPath); log.info("====Start get Server System Type =========="); Properties props=System.getProperties(); //获得系统属性集 String osName = props.getProperty("os.name"); //操作系统名称 log.info("Current OS Type :"+osName); log.info("====End get Server System Type =========="); osName = osName.toLowerCase(); int index = 0; index = osName.indexOf("windows"); String JDBC = "jdbc:sqlite:"+petternPath; if(index > -1){ petternPath = petternPath.toLowerCase(); JDBC="jdbc:sqlite:/"+petternPath; } log.info("path = "+petternPath); log.info("JDBC: "+JDBC); Connection conn = DriverManager.getConnection(JDBC); log.info("getPetternList conn="+conn.toString()); Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery("select * from pattern"); List<String> list = null; if(rs != null){ list = new ArrayList<String>(); } while (rs.next()) { String pid = rs.getString("pattern_id"); log.info("pattern_id = "+pid); list.add(pid); } rs.close(); conn.close(); deleteFile(newFile); return list; }只有这样做才能避免老是出现: