java连接sql server2008 ,驱动是sqljdbc.jar,运行错误是:用户 'sa' 登录失败。 50
代码如下:importjava.sql.Connection;importjava.sql.DriverManager;publicclassTest{publicsta...
代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
public class Test {
public static void main(String[] args) {
String driverName ="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=SuperMarketInfo_Data";
String userName = "sa";
String userPwd = "sa";
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
运行错误如下:
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.shuangyulin.DBUtils.Test.main(Test.java:18)
急啊!在线等!
请高手帮忙解决,谢谢! 展开
import java.sql.Connection;
import java.sql.DriverManager;
public class Test {
public static void main(String[] args) {
String driverName ="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=SuperMarketInfo_Data";
String userName = "sa";
String userPwd = "sa";
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
运行错误如下:
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.shuangyulin.DBUtils.Test.main(Test.java:18)
急啊!在线等!
请高手帮忙解决,谢谢! 展开
7个回答
2012-04-13
展开全部
一:检查一下服务器开了没!
二:换一个驱动,sqlsever数据库有两个驱动的,用另一个试一试!
三:用户名密码正确不检查下:
二:换一个驱动,sqlsever数据库有两个驱动的,用另一个试一试!
三:用户名密码正确不检查下:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你数据库的密码不是sa ,密码错误,所以等不上
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
端口看配置正确不,还有就是sa用户名和密码看对不!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String driverName ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是不是mysql服务没开启啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询