java 控制台输出sa登陆失败啥原因?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 控制台输出sa登陆失败啥原因?相关的知识,希望对你有一定的参考价值。

控制台输出
严重: Servlet.service() for servlet action threw exception
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。
是什么原因啊?请电脑高手给解决一下 谢谢

jdbc的链接数据库有问题,检查一下jdbc的驱动配置是不是有错误!
MySQL

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://host:port/database","user","password");

Oracle数据库(thin模式)

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@host:port:databse","user","password");

Timesten数据库(thin模式)

Class.forName("com.timesten.jdbc.TimesTenDriver");
Connection con = DriverManager.getConnection("jdbc:timesten:client:dsn=dsnname")

Microsoft SQL Server
Class.forName("net.sourceforge.jtds.jdbc.Driver ");
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");
or
Connection con = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password");

DB2
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ");
Connection conn= DriverManager.getConnection("jdbc:db2://localhost:5000/sample",user,password);

Firebird
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection con = DriverManager.getConnection("jdbc:firebirdsql://host:port/fdb_file_path","user","password");

PointBase(Server)
Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
Connection con = DriverManager.getConnection("jdbc:pointbase:server://host:port/databasename","user","password");

HSQLDB(Server)
Class.forName("org.hsqldb.jdbcDriver");
Connection con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:port/mydb","user","password");

Derby
这个少有人听说吧,cloudscape 应该听说过吧,该项目由此衍生
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection("jdbc:derby://host:port//mydb","user","password");

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection conn = DriverManager.getConnection("jdbc:derby:mynewDB", p);

cloudscape
Class.forName("com.cloudscape.core.JDBCDriver");
Connection conn = DriverManager.getConnection("jdbc:cloudscape:<DB>");

Class.forName("com.cloudscape.rmiJdbc.RJDriver");
Connection conn = DriverManager.getConnection("jdbc:rmi://<HOST>:<PORT>/jdbc:cloudscape:<DB>", user, passoword);

Postgresql
Class.forName("org.postgresql.Driver");
Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");

Informix
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:informix-sqli://host:port/myDB:INFORMIXSERVER=myserver","user","password");

Access
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
Connection con=DriverManager.getConnection("jdbc:odbc:Driver=MicroSoft Access Driver (*.mdb);DBQ=mdb的文件路径","user","password");

Sybase
Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:sybase:Tds:host:port?ServiceName=databasename","user","password");
参考技术A 看看你的sa用户密码对不对,你用的是SQL Server,就先打开SQL Server,然后用程序中所写的sa用户的密码登录下,看对不对,如果平时不输入密码,哪密码肯定是空,但是password地方不能省略。如果非空,哪就改成当前sa的密码。
或者登录SQL Server里面之后,在安全里面找到sa用户,改成程序中的密码就OK啦。本回答被提问者采纳
参考技术B 你的DB类的这样写就OK 带有创建和关闭方法
private String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String URL="jdbc:sqlserver://localhost:1433;databaseName="这里写上数据库名称";
private Connection connection;
public Connection openConnection() throws SQLException, ClassNotFoundException
if(this.connection==null || this.connection.isClosed())
Class.forName(DRIVER);
this.connection = DriverManager.getConnection(URL,"这里写上数据库登录名字","这里写上数据库登录密码");

return this.connection;

public void closeConnection()
try
if(this.connection != null && ! this.connection.isClosed())
this.connection.close();

catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
finally
this.connection = null;



所以你的错误应该是数据库登录名字错了只要改下就OK
参考技术C 把你数据库中sa的密码修改成和你程序中数据库访问类的密码一致 参考技术D 只有两种情况

1 数据库服务没开启

2 账号密码错误

以上是关于java 控制台输出sa登陆失败啥原因?的主要内容,如果未能解决你的问题,请参考以下文章

SqlServer sa 用户登录失败的解决方法

cosole.debug(this),在火狐浏览器控制台不输出google浏览器能输出是啥原因?

sql server 2008安装失败,这个是啥原因?

Appium进行自动化测试的时候,始终无反应,也没有日志输出,请问啥原因?

500 internal server error是啥原因

用户“sa”登陆失败