none
Connection to SQL server in jsp

    Question

  • 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.*" %>

    <html>
      <head>
        <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">
        -->

      </head>
     
      <body bgcolor= "#00ffff">
        <%
            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);
                 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);
                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>");
            }
         %>
        
      </body>
    </html>
    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

Answers

All replies