张东哲 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);

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮