Java连接Oracle Xe数据库

首先映入驱动包 ojdbc6.jar
路径为:
安装路径\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar

连接

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Test01 {
	public static void main(String[] args) {

		// 加载驱动
		try {
			Class.forName("oracle.jdbc.OracleDriver");
			System.out.println("驱动加载成功");
		} catch (ClassNotFoundException e) {
			System.out.println("驱动加载失败");
			e.printStackTrace();
		}

		// 建立连接
		Connection conn = null;
		try {
			conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "SCOTT", "TIGER");
			System.out.println("连接成功");
		} catch (SQLException e) {
			System.out.println("连接失败");
			e.printStackTrace();
		} finally {
			// 关闭连接
			try {
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}
}

在这里插入图片描述

发布了8 篇原创文章 · 获赞 0 · 访问量 167

猜你喜欢

转载自blog.csdn.net/weixin_44231438/article/details/104837288