`

Usefule Java Code Collection

    博客分类:
  • Java
阅读更多
=====================从classpath 获得文件 =======================

Properties APP_PROPERTIES = new Properties(); 
		String CONFIG_PROPERTIES_FILE = "YourPropertiesFileName.properties";
		/*retrieve resource file from classpath */
		URL url = ClassLoader.getSystemResource(CONFIG_PROPERTIES_FILE);
		logger.info("Loading application configuration properties: "+url);
		APP_PROPERTIES.load(url.openStream()); 




//=====================JDBC Batch update ========================



try {
		//...
		
		  Connection con =null;//TODO create your own connection
		  String mgrnum1 ="";//TODO prepare parameter mgrnum1
		  String deptnum1 ="";//TODO prepare parameter deptnum1
		  String mgrnum2 ="";//TODO prepare parameter mgrnum2
		  String deptnum2 ="";//TODO prepare parameter deptnum2
		  con.setAutoCommit(false);                   
		  PreparedStatement prepStmt = con.prepareStatement(    
		    "UPDATE DEPT SET MGRNO=? WHERE DEPTNO=?");           
		  prepStmt.setString(1,mgrnum1);                         
		  prepStmt.setString(2,deptnum1);
		  prepStmt.addBatch();                                   

		  prepStmt.setString(1,mgrnum2);                        
		  prepStmt.setString(2,deptnum2);
		  prepStmt.addBatch();
		  int [] numUpdates=prepStmt.executeBatch();             
		  for (int i=0; i < numUpdates.length; i++) {             
		    if (numUpdates[i] == -2)
		      System.out.println("Execution " + i + 
		        ": unknown number of rows updated");
		    else
		      System.out.println("Execution " + i + 
		        "successful: " +numUpdates[i] + " rows updated");
		  }
		  con.commit();                                           
		} catch(BatchUpdateException b) {
		  // process BatchUpdateException
		} 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics