第一種方式通過數據庫本身的JDBC Driver連接到數據庫 Classs
forName(
oracle
jdbc
driver
OracleDriver
);
Connection conn = DriverManager
getConnection(
jdbc:oracle:thin:@
:
:huihoo
scott
tiger
);
第二種方式通過JDBCODBC橋連接到數據庫 Class
forName(
sun
jdbc
odbc
JdbcOdbcDriver
);
Connection conn = DriverManager
getConnection(
jdbc:odbc:
scott
tiger
);
為數據源
完整的用戶登錄
Properties props = new Properties();
props
put(
user
scott
);
props
put(
password
tiger
);
Driver myDriver = (Driver) Class
forName(
oracle
jdbc
driver
OracleDriver
)
newInstance();
conn = nnect(
jdbc:oracle:thin:@
:
:huihoo
props);
conn
close();
System
out
println(
成功登錄
);
System
out
println(
歡迎您
+props
getProperty(
user
)+
!
);
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19780.html