Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    3

    Unanswered: Can't connect to SQL Server 2000

    I can't connect my jsp file to SQL Server 2000. Below is my code and the error result that i got.. Please help me to solve it..I have installed the driver and write them in the classpath..

    <%@page import="java.sql.*"%>
    <%
    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
    try {
    // Open Database connection
    Connection con = DriverManager.getConnection("jdbc:microsoft:sqlser ver://sansan:1433;databasename= coffeepassion","sa","sa");

    // Query Database (all queries use the same connection)
    String sql = "SELECT EmpID, EmpPassword FROM EmpLogin";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("sql");

    // Print header and each record returned
    out.println("List of items in the database:");
    while(rs.next())
    out.println(rs.getString("EmpID") + " " +rs.getString("EmpPassword"));
    // Finished using the database instances
    rs.close();
    stmt.close();
    con.close();
    }

    catch (Exception e) {
    out.println(e.toString()); // Error message to display
    }
    %>


    Error Result:

    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot open database requested in login ' coffeepassion'. Login fails.

  2. #2
    Join Date
    Dec 2002
    Posts
    1,245
    I don't have a lot of experience with jdbc, but here goes nothing:

    1. Should there be a space in between "database=" and "coffeepassion"?
    2. Can you make a connection from the web server to the database server using a .udl file (make a file, call it anything.udl, start it and use another driver type to connect)?\
    3. Are you sure you have the right password?

    One other thought; please consider using a different account to connect to SQL server. Once you've started down the development path using the sa account, it gets very difficult to make the decision to change to using a different account. Using sa leaves you exposed to all sorts of mischief.

    Regards,

    hmscott


    Quote Originally Posted by sansan
    I can't connect my jsp file to SQL Server 2000. Below is my code and the error result that i got.. Please help me to solve it..I have installed the driver and write them in the classpath..

    <%@page import="java.sql.*"%>
    <%
    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
    try {
    // Open Database connection
    Connection con = DriverManager.getConnection("jdbc:microsoft:sqlser ver://sansan:1433;databasename= coffeepassion","sa","sa");

    // Query Database (all queries use the same connection)
    String sql = "SELECT EmpID, EmpPassword FROM EmpLogin";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("sql");

    // Print header and each record returned
    out.println("List of items in the database:");
    while(rs.next())
    out.println(rs.getString("EmpID") + " " +rs.getString("EmpPassword"));
    // Finished using the database instances
    rs.close();
    stmt.close();
    con.close();
    }

    catch (Exception e) {
    out.println(e.toString()); // Error message to display
    }
    %>


    Error Result:

    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot open database requested in login ' coffeepassion'. Login fails.
    Have you hugged your backup today?

  3. #3
    Join Date
    May 2004
    Posts
    3

    another error

    dear hmscott,

    i've remove the space in the 'databasename= coffeepassion'..and get another error:

    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •