Connect to an Oracle database with JDBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {

  public static void main(String[] argsthrows Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(
        "jdbc:oracle:thin:@//server.local:1521/prod""scott""tiger");
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select * from employee");
    while (rset.next()) {
      System.out.println(rset.getString(1));
    }
    stmt.close();
  }
}

   

Comments

  1. hello could you make some totorial java + oracle database step by steps :D i would be thanks to you if you make that :D

    ReplyDelete

Post a Comment