Re: Newbie - a question about import and .jar statement
Arved Sandstrom wrote:
"Mark Space" <markspace@sbc.global.net> wrote in message
news:8uIik.34009$ZE5.9078@nlpi061.nbdc.sbc.com...
zalek wrote:
Now I have more questions:
1. which import statement should I use instead of
com.microsoft.sqlserver.jdbc.*;
Normally, none. Use "Class.forName()" and supply the driver name as a
parameter to the script or application.
<http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html>
Other useful references are:
1)
http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/drivermanager.html
2) http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/datasource.html
Note that DataSource is preferred if you can use it. As the docs point out,
the advantages of this over using DriverManager are (a) not hardcoding
driver info, and (b) taking advantage of connection pooling and distributed
transactions etc. Of course, as far as (a) is concerned the hardcoding for
DataSource is usually the right way, but it should be noted that:
- driver does not need to be hardcoded with DriverManager, it can be
made configurable as well
- you do not get connection pooling and distributed just by using
DataSource, some data sources (often those used in Java EE
contexts) *can* provide those features
Arne