张东哲 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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记