您的位置:jsp学习站首页 >> 数据库 >> ORACLE >> Java与Oracle的两种连接方式

Java与Oracle的两种连接方式

[ 来源:互网络 | 更新日期:2007-09-30 18:38:04 | 浏览次数:8943]
简介:forName("oracle
第一种方式:通过数据库本身的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")+"!");

 
Tags:关键字:Java与Oracle的两种连接方式
责任编辑:glen