第一种方式通过数据库本身的JDBC Driver连接到数据库
ClasssforName(oraclejdbcdriverOracleDriver);
Connection conn = DriverManagergetConnection(jdbc:oracle:thin:@::huihooscotttiger);
第二种方式通过JDBCODBC桥连接到数据库
ClassforName(sunjdbcodbcJdbcOdbcDriver);
Connection conn = DriverManagergetConnection(jdbc:odbc:scotttiger);
为数据源
完整的用户登录
Properties props = new Properties();
propsput(user scott);
propsput(password tiger);
Driver myDriver = (Driver) ClassforName(oraclejdbcdriverOracleDriver)newInstance();
conn = nnect(jdbc:oracle:thin:@::huihoo props);
connclose();
Systemoutprintln(成功登录);
Systemoutprintln(欢迎您 +propsgetProperty(user)+!);