日期:2014-05-16  浏览次数:20586 次

java连接oracle 入门odbc

?

?

public void testOracle() {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection conn = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:orcl", "system", "admin");
			System.out.println("连接成功!");
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("select * from stu_info_tab");
			while (rs.next()) {
				System.out.println("ok");
				System.out.println(rs.getInt("student_id"));
			}
			rs.close();
			stmt.close();
			conn.close();
		} catch (ClassNotFoundException e) {
			System.out.println("ClassNotFoundException");
		} catch (SQLException e) {
			System.out.println("SQLException");
		}
	}

?

备注:默认的用户名是system,密码是自己设定的,不能用sys或者是sysdba,这个只是角色