• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc connection to ms sql (urgent)

 
rudolf hitler
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
rudolf hitler
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic