张东哲 2013-11-02 13:21 采纳率: 0%
浏览 3015

[Microsoft][ODBC SQL Server Driver][SQL Server]用户 'huyaozhong' 登录失败。18456

<%

String url = "jdbc:odbc:Temdata";

    String username = "huyaozhong";
    String password = "123456";

    Connection con = null;
    try{

         out.println("Beforw first connection<br>");

         con = DriverManager.getConnection(url,username,"");
         out.println("After first connection<br>");
    }catch(SQLException e){

        out.println("First connection throws exception "+e.getMessage()+e.getCause()+e.getErrorCode()+"<br>");
    }        
    if(con == null){
         out.println("First connection was failed<br>");
    }else{

        out.println("First connection successs<br>");
    }
    try{

       out.println("Before load Driver class<br>");
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();


       out.println("After load Driver class<br>");
    }catch(ClassNotFoundException e){

       out.println("Exception occure when load Driver Class"+e.getMessage()+e.getCause()+e.getException()+"<br>");   
    }  
    try{


        out.println("Before second conenction<br>");

        con = DriverManager.getConnection(url,username,"");
        out.println("After second connection<br>");
    }catch(SQLException e){

         out.println("Exception occure when first connecte to database "+e.getMessage()+e.getCause()+e.getErrorCode()+"<br>");
    }
    if(con == null){
        out.println("seceond connection failed<br>");
    }else{

        out.println("seconde connection seccess");
    }
    try{

      if(con != null)
           con.close();
    }catch(SQLException e){

        out.println("Exception occure when the  connection closed"+e.getSQLState()+e.getCause()+"<br>");
    }
 %>

运行结果:
Beforw first connection
First connection throws exception [Microsoft][ODBC SQL Server Driver][SQL Server]用户 'huyaozhong' 登录失败。null18456
First connection was failed
Before load Driver class
After load Driver class
Before second conenction
Exception occure when first connecte to database [Microsoft][ODBC SQL Server Driver][SQL Server]用户 'huyaozhong' 登录失败。null18456
seceond connection failed

  • 写回答

1条回答

  • 天马321 2014-06-28 08:18
    关注

    -_-!
    楼主你并没有把密码设进去。。。
    con = DriverManager.getConnection(url,username,"");
    应该改成:
    con = DriverManager.getConnection(url,username,password);

    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题