package com.etc.cn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class BascDao {
public static void main(String[] args) {
Connection conn=null;
//加载数据步骤
//1.加载驱动
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//2.建立与数据库的连接
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","sa","sa123");
System.out.println("连接成功");
} catch (Exception e) {
e.printStackTrace();
}
finally{
if(conn!=null){
try {
conn.close();
System.out.println("成功关闭");
} catch (SQLException e) {
e.printStackTrace();
}
Java与数据库的连接——JDBC
最新推荐文章于 2024-07-07 20:57:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)