Get connection from DataSource : OracleDataSource « Database SQL JDBC « Java






Get connection from DataSource

 
import javax.sql.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;

public class DataSource {

  public static void main(String[] args){
    try{
      OracleDataSource ods = new OracleDataSource();

      ods.setUser("yourName");
      ods.setPassword("mypwd");
      ods.setDriverType("thin");
      ods.setDatabaseName("ORCL");
      ods.setServerName("localhost");
      ods.setPortNumber(1521);

      Connection conn = ods.getConnection();

    }catch(SQLException se){
      se.printStackTrace();
    }
  }
}

 








Related examples in the same category

1.Jndi DataSource
2.Oracle Connection Pool DataSource