Oracle:JDBC链接Oracle的DEMO

1、引入jar包:

2、DEMO:

java 复制代码
package jdbc;

import java.sql.*;

public class OracleConnectionExample {
	public static void main(String[] args) throws SQLException {
		Connection conn = null;
		PreparedStatement statement = null;
		try {
			// Register JDBC driver
			Class.forName("oracle.jdbc.driver.OracleDriver");

			// Open a connection
			System.out.println("Connecting to database...");
			conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "username", "password");
			System.out.println("Connected!");

			// Do something with the Database here
			String sql = "select * from aa_student";
			statement = conn.prepareStatement(sql);
			ResultSet resultSet = statement.executeQuery();
			while (resultSet.next()) {
				System.out.println("id:" + resultSet.getLong("id"));
			}
			statement.close();
			// Close the connection
			conn.close();
		} catch (SQLException se) {
			// Handle errors for JDBC
			se.printStackTrace();
		} catch (Exception e) {
			// Handle errors for Class.forName
			e.printStackTrace();
		} finally {
			// finally block used to close resources
			try {
				if (statement != null)
					statement.close();
				if (conn != null)
					conn.close();
			} catch (SQLException se) {
				se.printStackTrace();
			} // end finally try
		} // end try

		System.out.println("Goodbye!");
	}// end main
}// end OracleConnectionExample
相关推荐
沙漏无语38 分钟前
(二)TIDB搭建正式集群
linux·数据库·tidb
姚不倒44 分钟前
三节点 TiDB 集群部署与负载均衡搭建实战
运维·数据库·分布式·负载均衡·tidb
隔壁小邓1 小时前
批量更新方式与对比
数据库
数据知道1 小时前
MongoDB复制集架构原理:Primary、Secondary 与 Arbiter 的角色分工
数据库·mongodb·架构
人道领域1 小时前
苍穹外卖:菜品新增功能全流程解析
数据库·后端·状态模式
修行者Java1 小时前
(七)从 “非结构化数据难存储” 到 “MongoDB 灵活赋能”——MongoDB 实战进阶指南
数据库·mongodb
小哥哥咯1 小时前
Oracle 19c 与 MySQL 8.0 字符串数据类型对比
mysql·oracle
野犬寒鸦1 小时前
TCP协议核心:TCP详细图解及TCP与UDP核心区别对比(附实战解析)
服务器·网络·数据库·后端·面试
江一破1 小时前
InfluxDB 详细介绍
数据库·influxdb