Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jdbc and sql server

Status
Not open for further replies.

cmn2

Programmer
Mar 6, 2003
73
US
I have having great difficuly in getting the jdbc driver from Microsoft to connect to SQL Server 2000 (SP3). The code below is directly from the Microsoft site and my server is set to Mixed mode authetication.

The SQL Server error is "login failed for user 'myUserName'"
Does anyone have any experiece using this driver with SQL Server? I've have put in way too many hours on this already.

I would appreciate any help. Thank you

import java.*;
public class Connect{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "myServer";
private final String portNumber = "1433";
private final String databaseName= "Northwind";
private final String userName = "myUserName";
private final String password = "myPW";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor";

// Constructor
public Connect(){}

private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
}

private java.sql.Connection getConnection(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
...
 
I think the problem has more to do with SQL Server configuration than Java, but maybe you can have a look at this:

forum.java.sun.com/thread.jspa?threadID=455572&messageID=2086907

forum.java.sun.com/thread.jspa?threadID=457036&messageID=2087343

Cheers,
Dian
 
Thanks Dian for the leads. I am still working on this. I do have a follow-up question in the mean time.

If I were to build a jsp page that needed values from a database to populate a combobox, wouldn't I be wanting a connection that would not require a user name or password. I am a bit confused on how to use the sql driver in this case, as userName and password always seems to be required. What would be the proper way to call on a sql server database from java code to populate a combobox.

Thanks
 
I think that will strongly depend on how sensible the data is. You can always enable anonymous logon on the database, but I don't think it's to advicable.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top