JAVA¶ÁÈ¡×ÊÔ´ÎļþµÄNÖÖ·½·¨
ÈçºÎ¶ÁÈ¡×ÊÔ´Îļþ£º
£¨Ò»£©
Properties props = new Properties();
props.load(new FileInputStream("db.properties"));
£¨¶þ£©
blog.propertiesÎļþÈçÏÂ
dbdriver=oracle.jdbc.driver.OracleDriver
dburl=jdbc:oracle:thin:@127.0.0.1:1521:ora92
dbuser=blog
dbpwd=blog
--------------
public class Config {
public Config() {
this.initDBConfig();
}
public String DBdriver;
public String DBuser;
public String DBpwd;
public String DBurl;
private void initDBConfig() {
try {
ResourceBundle bundle = ResourceBundle.getBundle("blog");
DBdriver = bundle.getString("dbdriver");
DBurl = bundle.getString("dburl");
DBuser = bundle.getString("dbuser");
DBpwd = bundle.getString("dbpwd");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
----------------
public class DAO {
public DAO() {
}
public Connection getConnection() {
Connection conn = null;
Config config = new Config();
String DBdriver = config.DBdriver;
String DBuser = config.DBuser;
String DBpwd = config.DBpwd;
String DBurl = config.DBurl;
try {
Class.forName(DBdriver);
conn = DriverManager.getConnection(DBurl, DBuser, DBpwd);
}
catch (Exception ex) {
System.out.println("********************");
System.out.println("²»Äܵõ½Êý¾Ý¿âÁ¬½Ó");
System.out.println("DBdriv
Ïà¹ØÎĵµ£º
×î½üµÄDevoxx´ó»áÉÏ£¬Java 7½«°üº¬±Õ°üµÄÏûÏ¢ÁîºÜ¶àÈ˸е½Õñ·Ü——Õ⽫×öΪһ¸ö¶ÀÁ¢µÄJSR±»ÊµÏÖ¡£ÔÚÖÚ¶àJava 7еÄÓïÑÔÌØÐÔÖУ¬ÓÐһЩÏÖÔÚÒѾÍê³ÉÁË¡£Devoxx´ó»áµÄһλ²Î»áÕßÔÚ²©¿ÍÖб¨¸æÁËÏÂÃæÕâЩJava 7ÒѾÍê³ÉµÄ7´óй¦ÄÜ£º
1£©¶Ô¼¯ºÏÀàµÄÓïÑÔÖ§³Ö£»
2£©×Ô¶¯×ÊÔ´¹ÜÀí£»
3£©¸Ä½øµÄͨÓÃʵÀý´´½¨ÀàÐÍÍ ......
Java™ ÓïÑÔ°üº¬Á½ÖÖÄÚÔÚµÄͬ²½»úÖÆ£ºÍ¬²½¿é£¨»ò·½·¨£©ºÍ volatile ±äÁ¿¡£ÕâÁ½ÖÖ»úÖƵÄÌá³ö¶¼ÊÇΪÁËʵÏÖ´úÂëÏ̵߳ݲȫÐÔ¡£ÆäÖÐ Volatile ±äÁ¿µÄͬ²½ÐԽϲµ«ÓÐʱËü¸ü¼òµ¥²¢ÇÒ¿ªÏú¸üµÍ£©£¬¶øÇÒÆäʹÓÃÒ²¸üÈÝÒ׳ö´í¡£ÔÚÕâÆÚµÄ Java ÀíÂÛÓëʵ¼ù
ÖУ¬Brian Goetz ½«½éÉܼ¸ÖÖÕýȷʹÓà volatile ±äÁ¿µÄģʽ£¬²¢Õ ......
quartzÊǸÉɶµÄ£¿ ÈÎÎñµ÷¶ÈÓõÄ
ÈÎÎñµ÷¶ÈÊǸÉɶµÄ£¿¾ÍÊÇÔÚÔ¤¶¨µÄʱ¼ä×öÔ¤¶¨µÄÊÂ
1.ÔÚquartÍøÕ¾ÏÂ×îеÄJAR°ü
2.½¨¸öÏîÄ¿£¬°ÑquartzµÄJAR°ü¼ÓÈëµ½ÏîÄ¿
3.н¨Ò»¸öÈÎÎñ
public class MyJob implements org.quartz.Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionExceptio ......
1¡¢ÃæÏò¶ÔÏóµÄÌØÕ÷ÓÐÄÄЩ·½Ãæ
1.³éÏó£º
³éÏó¾ÍÊǺöÂÔÒ»¸öÖ÷ÌâÖÐÓ뵱ǰĿ±êÎ޹صÄÄÇЩ·½Ã棬ÒÔ±ã¸ü³ä·ÖµØ×¢ÒâÓ뵱ǰĿ±êÓйصķ½Ãæ¡£³éÏó²¢²»´òËãÁ˽âÈ«²¿ÎÊÌ⣬¶øÖ»ÊÇÑ¡ÔñÆäÖеÄÒ»²¿·Ö£¬ÔÝʱ²»Óò¿·Öϸ½Ú¡£³éÏó°üÀ¨Á½¸ö·½Ã棬һÊǹý³Ì³éÏ󣬶þÊÇÊý¾Ý³éÏó¡£
2.¼Ì³Ð£º
¼Ì³ÐÊÇÒ»ÖÖÁª½áÀàµÄ²ã´ÎÄ£ÐÍ£¬²¢ÇÒÔÊÐíºÍ¹Ä ......