Oracle ODBC dla Windows

Potrzebowałem dostępu do bazy Oracle przez ODBC. Niestety Oracle’owy driver odbc jest inny niż wszystkie :-), bo nie pozwala zdefiniować dostępu do bazy wprost, tylko należy użyć spójnego mechanizmu narzędzi Oracle’owych, definiującego połączenie. Mowa o

TNS (Transparent Network Substrate), co ja bym nazwał definicją połączenia (zamiast Przeźroczystego Substratu Sieciowego ;-)). TNS może pochodzić z kilku źródeł – lokalnego (specjalnego pliku) i globalnego – np. LDAP. Dzięki temu we wszystkich narzędziach bazodanowych Oracle, podajemy tylko nazwę połączenia zamiast każdorazowo określać wszystkie parametry połączenia. Rozwiązanie zmyślne, ale patrząc przez pryzmat problemów z konfiguracją – nieintuicyjne. 

Aby połączyć się przez Oracle ODBC, należy pobrać sterowniki. Ja znalazłem cały pakiet zwany ODAC (Oracle Data Access Component). Po zainstalowaniu należy zdefiniować TNS naszego połączenia. Do tego celu służy plik tnsnames.ora, który zawiera specjalną składnię. Poniżej podstawowa konfiguracja:

my_conn =
 (DESCRIPTION =
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = moj.serwer.pl)(PORT = 1521))
   )
 (CONNECT_DATA =
   (SERVICE_NAME = sid_uslugi)
 )
)

Ponadto należy poinstruować narzędzia Oracle w jaki sposób ma wyszukiwać definicji połączeń. Mowa tu o kolejności przeszukiwania oraz z których źródeł skorzystać (ww. lokalne i/lub globalne). Ustawiamy to w pliku sqlnet.ora. Tu potrzebujemy tylko:

*NAMES.DIRECTORY_PATH= (TNSNAMES) *

Oba pliki należy umieścić w (już istniejącym) katalogu
%KATALOG_INSTALACJI_ODAC%\product\11.2.0\client_1\Network\Admin

Teraz można już korzystać z ODBC. Jeśli mieliście otwarty program korzystający z połączenia, to dla pewności należy go uruchomić ponownie.

You May Also Like

Private fields and methods are not private in groovy

I used to code in Java before I met groovy. Like most of you, groovy attracted me with many enhancements. This was to my surprise to discover that method visibility in groovy is handled different than Java!

Consider this example:

class Person {
private String name
public String surname

private Person() {}

private String signature() { "${name?.substring(0, 1)}. $surname" }

public String toString() { "I am $name $surname" }
}

How is this class interpreted with Java?

  1. Person has private constructor that cannot be accessed
  2. Field "name" is private and cannot be accessed
  3. Method signature() is private and cannot be accessed

Let's see how groovy interpretes Person:

public static void main(String[] args) {
def person = new Person() // constructor is private - compilation error in Java
println(person.toString())

person.@name = 'Mike' // access name field directly - compilation error in Java
println(person.toString())

person.name = 'John' // there is a setter generated by groovy
println(person.toString())

person.@surname = 'Foo' // access surname field directly
println(person.toString())

person.surname = 'Bar' // access auto-generated setter
println(person.toString())

println(person.signature()) // call private method - compilation error in Java
}

I was really astonished by its output:

I am null null
I am Mike null
I am John null
I am John Foo
I am John Bar
J. Bar

As you can see, groovy does not follow visibility directives at all! It treats them as non-existing. Code compiles and executes fine. It's contrary to Java. In Java this code has several errors, pointed out in comments.

I've searched a bit on this topic and it seems that this behaviour is known since version 1.1 and there is a bug report on that: http://jira.codehaus.org/browse/GROOVY-1875. It is not resolved even with groovy 2 release. As Tim Yates mentioned in this Stackoverflow question: "It's not clear if it is a bug or by design". Groovy treats visibility keywords as a hint for a programmer.

I need to keep that lesson in mind next time I want to make some field or method private!

Micro services on the JVM part 1 – Clojure

Micro services could be a buzzword of 2014 for me. Few months ago I was curious to try Dropwizard framework as a separate backend, but didn’t get the whole idea yet. But then I watched a mind-blowing “Micro-Services Architecture” talk by Fred George. Also, the 4.0 release notes of Spring covers microservices as an important rising trend as well. After 10 years of having SOA in mind, but still developing monoliths, it’s a really tempting idea to try to decouple systems into a set of independently developed and deployed RESTful services.

Micro services could be a buzzword of 2014 for me. Few months ago I was curious to try Dropwizard framework as a separate backend, but didn’t get the whole idea yet. But then I watched a mind-blowing “Micro-Services Architecture” talk by Fred George. Also, the 4.0 release notes of Spring covers microservices as an important rising trend as well. After 10 years of having SOA in mind, but still developing monoliths, it’s a really tempting idea to try to decouple systems into a set of independently developed and deployed RESTful services.