JAVA³£ÓòÙ×÷Óï¾ä ÏîÄ¿ÖеÄ×ܽáÈý
»ñµÃmysqlºÍoracleÁ´½ÓµÄÀà
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectDB {
private static final String MYSQL = "jdbc:mysql://";
private static final String ORACLE = "jdbc:oracle:thin:@";
private ConnectDB() {
}
public static Connection getInstance(String DBType, String url)
throws NoSuchDBException, SQLException
{
if ("mysql".equalsIgnoreCase(DBType))
return getMySqlConn(url);
if ("oracle".equalsIgnoreCase(DBType))
return getOracleConn(url);
return null;
}
public static void closeConn(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private static Connection getMySqlConn(String url) throws SQLException {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
conn = DriverManager.getConnection(MYSQL + url, "root", "root");
return conn;
}
private static Connection getOracleConn(String url) throws SQLException {
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
conn = DriverManager.getConnection(ORACLE + url, "scott", "tiger");
return conn;
}
}
Êý¾Ý¿âÁ´½ÓÀà——Í¨¹ýÅäÖÃÎļþ
/*
* Db.java
Created on 2007Äê8ÔÂ20ÈÕ, ÉÏÎç 8:37
*/
import
java.io.
*
;
import
java.sql.
*
;
import
java.util.Properties;
public
class
Db {
private
String driver;
private
String url;
private
String user;
private
String password;
private
Connection conn;
private
Statement stm;
private
ResultSet rs;
public
Db(){
this
(
"
DBConf.properties
"
);
}
Ïà¹ØÎĵµ£º
1. ¼òµ¥¹¤³§:
(1). ´´½¨Êä³ö(Output)½Ó¿Ú
package stone;
public interface Output {
public int MAX_COUNT =10; // ×î¶à¿É´òÓ¡¶àÉÙÌõ¼Ç¼
public void show(); ......
(1). ´´½¨Ò»¸ö½Ó¿Ú, Òª´úÀíµÄÀàºÍ ´úÀíÀ඼½«¼Ì³ÐËü
package stone;
public interface Image {
public void show();
}
(2). ´´½¨Òª±»´úÀíµÄÀà:
package stone;
public class BigImage implements Image {
public BigImage() {
......
jdk6ºÍjdk5Ïà±ÈµÄÐÂÌØÐÔÓУº
1¡¢instrumentation
ÔÚ Java SE 6 ÀïÃ棬instrumentation °ü±»¸³ÓèÁ˸üÇ¿´óµÄ¹¦ÄÜ£ºÆô¶¯ºóµÄ instrument¡¢±¾µØ´úÂë instrument£¬ÒÔ¼°¶¯Ì¬¸Ä±ä classpath µÈµÈ¡£
2¡¢HttpÓÐËùÔöÇ¿
3¡¢ Java ¹ÜÀíÀ©Õ¹£¨JMX£© ¼Ü¹¹¼°Æä¿ò¼Ü£¬ÒÔ¼°ÔÚ Java SE 5 ÖÐÐÂÒýÈëµÄ JMX API -- java.l ......
¹Ø¼ü×Ö: µ×²ãÊý¾Ý Ãû´Ê½âÊÍ£º ²¹Â룺1 ÔÚ¼ÆËã»úϵͳÖУ¬ÊýÖµÒ»ÂÉÓв¹ÂëÀ´±íʾ(´æ´¢). ʹÓò¹Âë,¿ÉÒÔ½«·ûºÅλºÍÆäËûλͳһ´¦Àí;ͬʱ,¼õ·¨Ò²¿É°´¼Ó·¨À´´¦Àí.ÁíÍâ,Á½¸öÓò¹Âë±íʾµÄÊý¾ÝÏà¼Óʱºò,Èç¹û×î¸ßλ(·ûºÅλ)Óнøλ,Ôò½øÎ¥±»ÉáÆú. 2 ²¹ÂëÓëÔÂëµÄת»»¹ý³Ì¼¸ºõÊÇÏàͬµÄ ÊýÖµµÄ²¹Âë±íʾҲ·ÖÁ½ÖÖÇé¿ö£º £¨1£©ÕýÊýµÄ²¹Âë:ÓëÔ ......