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.SQLServerDriver");
try {
// Open Database connection
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://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.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
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.SQLServerDriver");
try {
// Open Database connection
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://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.|||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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment