Java与Oracle的两种连接方式
2008-01-05 09:56:04 来源:WEB开发网核心提示:第一种方式:通过数据库本身的JDBC Driver连接到数据库Classs.forName("Oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin
第一种方式:通过数据库本身的JDBC Driver连接到数据库
Classs.forName("Oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.33:1521:huihoo","scott","tiger");
第二种方式:通过JDBC-ODBC桥连接到数据库
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:192.168.1.33","scott","tiger");
192.168.1.33为数据源
完整的用户登录
PRoperties props = new Properties();
props.put("user", "scott");
props.put("passWord", "tiger");
Driver myDriver = (Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = myDriver.connect("jdbc:oracle:thin:@192.168.1.33:1521:huihoo", props);
conn.close();
System.out.println("成功登录.");
System.out.println("欢迎您 "+props.getProperty("user")+"!");
更多精彩
赞助商链接