File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes connecting Java with MS SQL2000 or 7.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "connecting Java with MS SQL2000 or 7.0" Watch "connecting Java with MS SQL2000 or 7.0" New topic

connecting Java with MS SQL2000 or 7.0

Rafal Chmielecki

Joined: Apr 04, 2001
Posts: 5
I have no experience with this - could you help me with this? i dont know exactly how to get a connection with mssql. I did it before using asp, but now I have to use JSP.
best regards
Rafal Chmielecki

Rafal Chmielecki<BR>Pogrammer<BR>Inteligo S.A.(Warsaw, Poland)
Franck Rasolo

Joined: May 29, 2001
Posts: 21
Perhaps, you should start from the JDBC Basics from the Java Tutorial.
Also, you may want to purchase a good book on JSP such as Java Server Pages from Hans Bergsten, available from all major bookstores.

Franck Rasolo
Independent Java Consultant
London, UK

<i>Franck Rasolo<br />Independent Consultant<br />London, UK</i>
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
The steps are as follows :
1.Create an ODBC DSN
Using the Windows Control Panel, create an ODBC DSN (data source name) for the database.
2.Load the driver
In a JDBC program, one of the first things to do is to load the JDBC driver by calling the forName() static method of the Class class. forName() takes one string parameter: the name of the driver along with its package. For JavaSoft's JDBC-ODBC Bridge, this string is "sun.jdbc.odbc.JdbcOdbcDriver". Therefore, the call would look like:
3.Establish a database connection
Once the JDBC driver loads, you can establish a connection to the database using the DriverManager.getConnection() method. This method's first argument is a string that contains the JDBC URL for the database. The second and third parameters are the user name and password, respectively.
A JDBC URL is formulated using the following pattern:
A connection to the database could be established in this manner:
String stUrl_= "jdbcdbc:myDSN"; // let's say myDSN
// is the name of ODBC DSN
Connection connection_ = DriverManager.getConnection(stUrl_, "sa", "");
Hope that helps.

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
I agree. Here's the link:
subject: connecting Java with MS SQL2000 or 7.0
It's not a secret anymore!