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
相关推荐
不是起点的终点12 分钟前
【实战】Python 一键生成数据库说明文档(对接阿里云百炼 AI,输出 Word 格式)
数据库·python·阿里云
2301_813599552 小时前
Go语言怎么做秒杀系统_Go语言秒杀系统实战教程【实用】
jvm·数据库·python
NCIN EXPE7 小时前
redis 使用
数据库·redis·缓存
MongoDB 数据平台7 小时前
为编码代理引入 MongoDB 代理技能和插件
数据库·mongodb
极客on之路7 小时前
mysql explain type 各个字段解释
数据库·mysql
代码雕刻家7 小时前
MySQL与SQL Server的基本指令
数据库·mysql·sqlserver
lThE ANDE7 小时前
开启mysql的binlog日志
数据库·mysql
yejqvow127 小时前
CSS如何控制placeholder文字的颜色_使用--placeholder伪元素
jvm·数据库·python
oLLI PILO7 小时前
nacos2.3.0 接入pgsql或其他数据库
数据库
m0_743623927 小时前
HTML怎么创建多语言切换器_HTML语言选择下拉结构【指南】
jvm·数据库·python