1、加载ojdbc.jar驱动(路径:E:\myoracle\oracle\product\11.2.0\dbhome_1\jdbc\lib)

2、String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "tiger";
Class.forName(driver);

package com.db;

import java.sql.*;
public class oracleDb {
public static void main(String[] args) throws ClassNotFoundException{ 
String driver = "oracle.jdbc.driver.OracleDriver";
// URL指向要访问的数据库名
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "tiger";
Class.forName(driver);
try {
// 加载驱动程序
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed()){
System.out.println("Succeeded connecting to the Database!");
}
// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from student";
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

相关文章:

  • 2021-07-10
  • 2021-10-11
  • 2021-10-17
  • 2021-10-20
  • 2021-08-07
  • 2021-11-21
猜你喜欢
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
相关资源
相似解决方案