Solution to the problem that JSP can’t connect to SQL Server 2008


1. First of all, if you encounter javax.servlet.ServletException : java.lang.ClassNotFoundException : . sqlserver.SQLServerDriver This is a mistake,

So you should Class.forName (” . sqlserver.SQLServerDriver “);

Change to Class.forName (” . jdbc.SQLServerDriver “);

2. When the error is javax.servlet.ServletException : java.sql.SQLException : No suitable driver found for jdbc:microsoft : sqlserver://localhost : 1034; databasename = test2 >,

The string URL should be=“ jdbc:microsoft : sqlserver://localhost :1034;DatabaseName=test2″;

Change to string URL=“ jdbc:sqlserver :// localhost:1034;DatabaseName=test2 “;

3. Error is javax.servlet.ServletException : . jdbc.SQLServerException : unable to open database ‘test2’ requested by login. Login failed.

There are many ways to solve this problem on the Internet, such as checking the driver, user permissions and so on. I repeatedly create users and set permissions, which has not been successful.. Finally, I went to the configuration manager to check the dynamic port of ipall of TCP / IP in the network configuration, and found that it is not the usual 1433, but 1034. Then I changed it in the code… In addition, you should pay attention to the user permissions in SQL server, otherwise it is easy to cause problems