搞了一天了,还是没有解决
由于需要用到SQLServer,数据库登录方式是Sqlserver和Windows混合登录,在Microsoft SQL Server Management Studio中可以用sa账户登录,但是在Java代码中登录不了,这是为什么?求大牛指点:
[code="java"]import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBtest {
public static void main(String[] args){
String URL="jdbc:sqlserver://192.168.88.201:1433;databaseName=master";
String USERNAME="sa";
String PASSWORD="123";
String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Connection conn = null;
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println(conn);
}
}
[/code]
代码没有问题,也能用Microsoft SQL Server Management Studio中可以用sa账户登录,就是用Java连不上/抛异常是:
[code="java"]com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
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:2529)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBtest.main(DBtest.java:15)[/code]