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
相关推荐
万邦科技Lafite21 分钟前
利用淘宝商品详情接口获取商品价格,监控商品价格浮动
数据库·api·开放api接口·淘宝开放接口
深藏功yu名1 小时前
Day24:向量数据库 Chroma_FAISS 入门
数据库·人工智能·python·ai·agent·faiss·chroma
知识分享小能手1 小时前
MongoDB入门学习教程,从入门到精通,MongoDB创建、更新和删除文档(3)
数据库·学习·mongodb
chehaoman1 小时前
MySQL的索引
android·数据库·mysql
cm6543201 小时前
用Python破解简单的替换密码
jvm·数据库·python
还是做不到嘛\.2 小时前
DVWA靶场-Brute Force
运维·服务器·数据库·学习
老张聊数据集成2 小时前
ETL是什么?一文讲清ETL和ELT的区别
数据库
Oueii2 小时前
掌握Python魔法方法(Magic Methods)
jvm·数据库·python
Elastic 中国社区官方博客3 小时前
现已正式发布: Elastic Cloud Hosted 上的托管 OTLP Endpoint
大数据·运维·数据库·功能测试·elasticsearch·全文检索