Connection to SQL server in jsp


  • i'm trying to connect sql server in jsp,here is all my codes:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page import = "java.sql.*" %>

        <base href="<%=basePath%>">
        <title>Test page for connection</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <link rel="stylesheet" type="text/css" href="styles.css">

      <body bgcolor= "#00ffff">
            String url = "jdbc:odbc:Temdata";
            String username = "huyaozhong";
            String password = "123456";

            Connection con = null;
                 out.println("Beforw first connection<br>");
                 con = DriverManager.getConnection(url);
                 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>");
                out.println("First connection successs<br>");
               out.println("Before load Driver class<br>");
               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>");   
                out.println("Before second conenction<br>");
                con = DriverManager.getConnection(url);
                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>");
                out.println("seconde connection seccess");
              if(con != null)
            }catch(SQLException e){
                out.println("Exception occure when the  connection closed"+e.getSQLState()+e.getCause()+"<br>");
    but result shows: [Microsoft][ODBC SQL Server Driver][SQL Server]user  sing in failed     18456

    i checked the username and password ,both are right and i can sing in my database .i don't know why here tell me user cannot sing in?

    • Moved by Kalman Toth Saturday, November 02, 2013 4:05 PM Not t-sql
    Saturday, November 02, 2013 4:00 PM


All replies