2 u012361118 u012361118 于 2013.11.02 21:21 提问

[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个回答

qwuack
qwuack   2014.06.28 16:18

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!