import java.sql.*;
public class Test {
public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=account"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "qgz08254578 "; //密码
Connection dbConn;
try{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println( "Connection Successful! "); //如果连接成功 控制台输出Connection Successful!
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
/////////////////////*
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Test.main(Test.java:14)
*/
我先导入了sqljdbc.jar的包不行,百度上找到说用这个jtds-1.2.5还是不行。。。真的不知道怎么搞了
希望大家多多帮忙,小弟感激不尽
------解决方案--------------------