Cross−Reference The installation process requires the use of the JNDI classes...
Serwis znalezionych hasełOdnośniki
- Smutek to uczucie, jak gdyby się tonęło, jak gdyby grzebano cię w ziemi.
- METODY ZAGĘSZCZANIA BETONU NA BUDOWIE Aby do tego nie dopuścić, niezbędne są nadzór i kontrola bieżąca procesu zagęszczania na budowie...
- Rozwój fizyczny, jako proces irnian somatycznycH (anatomicznych) i funkcjonalnych (fizjologicznych) w organizmie, stwarza podstawy dla rozwoju motoryki...
- - Szczęście osiąga w procesie nieustannie realizowanej pełni życia i niezależne jest od celu, jaki pozwoli zrealizować los; a tam gdzie życie pełne, na miarę...
- N- ACETYLOCYSTEINAN-acetylocysteina (NAC) stanowi najczęstszą postać cysteiny i ma szczególne znaczenie w procesach odtruwania...
- Autorzy tego badania wysunęli przypuszczenie, że leki te mogły uniemożliwić pacjentom poleganie na sobie i zakłócić przebiegający w naturalny sposób proces...
- Przykład ten pokazuje, że nabieranie dystansu i przyjmowanie różnych ról badawczych jest elastycznym procesem, wymagającym od badacza dużej pomysłowości i...
- mamy do czynienia z określonym następstwem poszczególnych stadiów, z których jedneprzychodzą po drugich, ale z procesem, w którym wszelkie elementy są ze...
- (1) upowszechnienie wiedzy o człowieku jabezpośrednio po wystąpieniu choroby albo gicznego procesu starzenia się, w jakim zaś pienia...
- Proces radzenia sobie ze zmianami w zwiÄ…zku intymnym przebiega podobnie...
- wystarczająco długo, aby pojawiły się świadome procesy przetwarzania...
Smutek to uczucie, jak gdyby się tonęło, jak gdyby grzebano cię w ziemi.
If you want to read more about JNDI before continuing with this chapter, we recommend the LDAP primer in Chapter 8, "Working with Directory Services and LDAP" and an introduction to JNDI in Chapter 9, "Accessing Directory Services with JNDI."
Loading the driver
Enterprise drivers are represented by the interface javax.sql.DataSource. Unlike the core classes, enterprise drivers have no manager to load them in. There is also no need for you to go through an explicit registration step the way the core drivers did. When you are operating in the enterprise environment, it is assumed that the environment has already loaded and registered all the drivers you are going to need before your application starts. If you have downloaded a third−party driver, you will need to go to the management console or configuration files of your middleware system to register the new code.
Compared to the core Driver, DataSource offers fewer options for a database connection. Where there were four options for the core classes, you now only have two — a default and one that supplies a user name and password. You don't need to provide a URL when requesting the actual connection: This is because the assumptions are quite different within the enterprise setting. Drivers here assume that you are going to connect to a particular database, and all the information is specified in the properties that are used to register the data source in the first place. Changing the database requires the use of that middleware's management tool.
Requesting a data source still requires you to name which one you want. The name is represented as a string that always starts with jdbc/. Following this is the name you have assigned to the data source in the middleware−management tool. For example, if you have loaded an Oracle driver, you might use the name jdbc/Oracle. If your middleware is using two different databases, then you might use names such as jdbc/oracle_payments and jdbc/oracle_staff. These names can be whatever you want, so you could instead specify, say, the names jdbc/oracle/payments and jdbc/oracle/staff.
Once you have settled on a name for your driver, you might actually want to use it! To do this, you make use of the JNDI naming classes to name, locate, and then load a driver. JNDI, as you will read in later chapters, provides a directory−type view of resources. Just as your computer's file system name starts with / or c:\
before you find the lower−level directories, you will need to provide a top−level area for the drivers. This area is represented by the InitialContext class that is part of the javax.naming package: InitialContext ctx = new InitialContent();
With the root of your context information established, you need to provide the "path" to your driver. The path is the name that you chose earlier. When you provide the path, you ask the context to search it and find the object that it represents. In directory services–speak, this is called a lookup (you might be already familiar with the term from RMI's rmiregistry, which is a form of directory service). Fetching your DataSource instance is performed with the following call:
123
Chapter 7: Using JDBC to Interact with SQL Databases DataSource ds = (DataSource)ctx.lookup("jdbc/Oracle");
And that's all there is to it. You now have a live data source to ask for connections to the database with.
Requesting a new connection through the getConnection() methods, as follows: Connection simple_conn = ds.getConnection();
Connection passwd_conn =
ds.getConnection("javauser", "password");
Of course, remember to catch the SQLExceptions and check for warnings as well.
Registering a Driver with the System