I have to write down some of the problems that I have encountered many times. The lessons have been delayed for a lot of time.
Problem description
Write a code to connect to the Database SQL Server in Java;
As follows:
Import java. SQL .*;
Public class tosql2000 {
Public static void main (string [] SRG ){
String drivername = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"; // load the JDBC driver
String dburl = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = Try"; // connect to the server and database sample
String username = "sa"; // Default User Name
String userpwd = ""; // Password
Connection dbconn;
Try {
Class. forname (drivername );
Dbconn = drivermanager. getconnection (dburl, username, userpwd );
System. Out. println ("connection successful! "); // If the connection is successful, the console outputs connection successful!
} Catch (exception e ){
E. printstacktrace ();
}
}
}
When running, eclipse reports the following error: [Microsoft] [SQL Server 2000 driver for JDBC] [sqlserver] user 'sa 'Logon Failed. This user is not associated with a trusted SQL server connection.
If the user name and password are determined to be correct, make sure that JDBC is correct and patch SP3 is installed.
Still unsolved.
Finally, modify the settings in the Enterprise Manager of SQL Server, for example:
Solve the problem.