1、项目加载数据库jar包
2、
package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SimpleDatabase {
public static void main(String[] args) throws ClassNotFoundException,SQLException{
//安装驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott", "tiger");
Statement statement = conn.createStatement();
String sql = "Select * from emp";
ResultSet result = statement.executeQuery(sql);
while(result.next()){
String ename = result.getString(2);
System.out.println(ename);
}
}
}