App下載
首頁(yè)javaconnectionJava JDBC - 如何連接到Oracle瘦客戶(hù)機(jī)

Java JDBC - 如何連接到Oracle瘦客戶(hù)機(jī)

我們想知道如何連接到Oracle瘦客戶(hù)機(jī)。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
  public static void main(String[] argv) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("Oracle driver registered");
    Connection conn = null;
    conn = DriverManager.getConnection(
        "jdbc:oracle:thin:@localhost:1521:orclh", "scott", "tiger");

    Statement stmt = conn.createStatement();
    ResultSet r = stmt.executeQuery("Select * from emp");
    while (r.next()) {
      String str = r.getString("ename");
      System.out.println(str);
    }
  }
}