my dog learned polymorphism*
The moose likes JDBC and the fly likes Connecting to SQL server db over a LAN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting to SQL server db over a LAN" Watch "Connecting to SQL server db over a LAN" New topic
Author

Connecting to SQL server db over a LAN

Jyothsna Sri Y
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
Hi,
I wish to connect to a database existing on another machine on the LAN, given the server name, IP address, login and password for the db.How can I do it?
Thanks.
Cheers
Jyothsna.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

DriverManager.getConnection() takes a URL, user name and password as arguments. Check your JDBC driver documentation to see exactly how the URL is constructed. For example the JDBC-ODBC bridge starts with

[ September 25, 2003: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Darn smilies. that should be jdbc, a colon, then odbc.
Jyothsna Sri Y
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
Hey Joe,
Thanks a ton for the immediate response. But it's urgent!!!
I wanted to know how to connect to a database which exists on another system named for example "WorkStation40" where the table name is "PQR" and the user name is "abc" and password "123". How am I supposed to frame the URL?
Where does it go in the general code of type:
String url = new String("jdbc dbc sn");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,"abc","123");
Thanks.
cheers
Jyothsna.
Jyothsna Sri Y
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
That was supposed to be jdbc followed by a colon followed by odbc, colon dsn.
Jyothsna
Rema Remulta
Ranch Hand

Joined: Apr 03, 2002
Posts: 51
hi,
In case you haven't found the solution of the problem, this is how to do it:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://10.0.0.1:1669;DatabaseName=" + database + ";User=" + userID + ";Password=" + pwd + "");
 
 
subject: Connecting to SQL server db over a LAN
 
Similar Threads
SocketException
Hardware Spec
testing
communication with LAN server through mobile
Is there any method to get address of all machines in network