On 14 ago, 21:09, zalek <zalekbl...@hotmail.comwrote:
Quote:
Hello,
>
I wrote a program that is working OK which *access DB2 using the
following code:
>
String w_conn = "jdbc:db2:DB2MAIN;
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Connection db2Conn =
DriverManager.getConnection(w_conn,w_userid,w_pass w);
>
Now I am reading I can access DB2 using JDNI service where code is
like this:
>
Connection conn = null;
try {
* * *Context initialContext = new InitialContext();
* * *DataSource ds = (DataSource)initialContext.lookup(w_service);
* * *conn = ds.getConnection();
>
Which way is consider more efficient?
>
What is the variable w_service? I understand w_service is a String –
name of DB2 service, but what is a value of this string?
>
Thanks,
>
Zalek
|
Hi Zalek,
Since you have access to use the datasource then i suggest you do, i
always prefer using it because is more flexible for my programing.
For example, you can change the user/password, the database name, the
server name or port number...only by modifying the DataSource
configuration without changing any line of your code.
About the w_service variable, its the jndi name of the Datasource
created in the application server. The standar for this name is "jdbc/
MyDatasource" (notice the jdbc/ prefix).
good luck!