aspose file tools*
The moose likes JDBC 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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connecting Java with MS SQL2000 or 7.0" Watch "connecting Java with MS SQL2000 or 7.0" New topic
Author

connecting Java with MS SQL2000 or 7.0

Rafal Chmielecki
Greenhorn

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
Greenhorn

Joined: May 29, 2001
Posts: 21
Rafal,
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:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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:
jdbc:<subprotocol>:<subname>
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.
Parmeet


Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connecting Java with MS SQL2000 or 7.0