Java + Maven +PostgreSQL/Oracle/MySQL连接配置
1. Java + Maven 配置连接Oracle数据库
添加maven依赖
<dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>21.5.0.0</version> </dependency>
建立数据库连接
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Connector { public static Connection getOracleConnection() throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载数据库驱动 String url = "jdbc:oracle:thin:@172.1.0.0:1521:orcl"; // 连接URL String username = "admin"; String password = "123456"; Connection connection = DriverManager.getConnection(url, username, password); return connection; } }