本人用的是MyEclipse10 ,JAVA用的是1.7,oracle用的是database 11g

import java.sql.*;


public class TestJDBC {
	public static void main(String[] args) {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		
		try {
				Class.forName("oracle.jdbc.driver.OracleDriver");
				//new oracle.jdbc.driver.OracleDriver();
				conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
				stmt = conn.createStatement();
				rs = stmt.executeQuery("select * from  dept");
				while(rs.next()) {
					System.out.print(rs.getString("deptno") + " ");
					System.out.println(rs.getString("dname"));
				}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(rs != null) {
					rs.close();
					rs = null;
				}
				if(stmt != null) {
					stmt.close();
					stmt = null;
				}
				if(conn != null) {
					conn.close();
					conn = null;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
	}
}

随机文章

给android模拟器安装apk
给android模拟器安装apk

360搜索突破15%也推onebox,百度,你怎么看
360搜索突破15%也推onebox,百度,你怎么看

里程碑换屏图文教程
里程碑换屏图文教程

Zaker已在解决进入频道空白问题
Zaker已在解决进入频道空白问题

内容分享:道招
本文链接:java jdbc连接oracle数据库
道招声明:除特别标注或作者不详外,本站所有文章均为原创,转载请注明。欢迎共同关注互联网!