permaculture playing cards*
The moose likes JDBC and the fly likes jdbc connection to ms sql (urgent) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc connection to ms sql (urgent)" Watch "jdbc connection to ms sql (urgent)" New topic
Author

jdbc connection to ms sql (urgent)

rudolf hitler
Ranch Hand

Joined: Feb 07, 2003
Posts: 34
Hi,
I would like to know how to connect to a ms sql database using jdbc.Can u please forward some code for the connections.I have downloaded the microsoft sql driver for jdbc i would also like to know how do i configure it to use it for jdbc
(i.e setting classpaths)
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
Madhu,
Below a test that I first worked with when I wanted to get to know JDBC:

SAMTEST is the DSN entry that I created in the ODBC manager on this win2000 PC. Hope this helps!


We make a living by what we get, we make a life by what we give!
rudolf hitler
Ranch Hand

Joined: Feb 07, 2003
Posts: 34
hi,
Well ur prog didnt work it gave an sql exception
sayin "no suitable driver" i tried the same kinda prog before posting the message.can u help further
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
Did you set up a user or system DSN? This must be in place in order to use the code that I posted. Post your error output.
rudolf hitler
Ranch Hand

Joined: Feb 07, 2003
Posts: 34
well i did create a dsn.
The error is:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at ODBCTest.main(ODBCTest.java:1)
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
Madhu, I created a User DSN in the ODBC Data Source Administrator. The Windows DSN Name = SAMTEST, and the Database name is samtest. It appears that your code is yacking on line 1. What is there? I am assuming that you are getting this to compile?!?!
Fred Wilson
Greenhorn

Joined: Feb 20, 2003
Posts: 2
I've got this code:
Connection con;
String strUrlTest = "jdbc:microsoft:sqlserver://USPLSxxx333:1433;" +
"HostProcess=TRANSWITCH;DatabaseName=appsvr;" +
"SelectMethod=Cursor;" +
"User=tran_owner;Password=tranownpw";
try {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ).newInstance();
} catch( ClassNotFoundException e ) {
} catch( InstantiationException e ) {
} catch( IllegalAccessException e ) {
} // end try/catch sequence
try {
con = DriverManager.getConnection( strUrlTest );
} catch( SQLException e ) {
} // end try/catch sequence
In this case USPLSxxx333 is the computer name and 1433 is the port MsSql listens on. This port can be anything, you must find out what it is in your db setup. There's a couple of ways to find this port, one way is to view the db startup msgs and another way is a db setup tool, poke around, you'll find the port eventually. HostProcess, DatabaseName, User, and Password are all also specific to you db. Your dba should know these things.
Fred Wilson
Greenhorn

Joined: Feb 20, 2003
Posts: 2
Concerning my last post, I suppose it would be helpful to specify that I'm using the Microsoft JDBC server to access a Microsoft SQL 2000 database. No ODBC required.
 
wood burning stoves
 
subject: jdbc connection to ms sql (urgent)
 
Similar Threads
Connecting to SQL Server 2000
Where to get JDBC for Wince ?
Fetching Image Data
Database URL
JDBC to MS SQL Server