Two days a classmate said connecting SQL Server 2000 is always unsuccessful, do not understand why, online search for a long time did not find a substantive answer. So I took over and wanted to challenge this "great challenge". But unfortunately, I didn't make it all night. At first it was not to the class, and later found that the package was not imported. But the problem has not been solved and emerged. [Microsoft][sqlserver Driver for Jdbc]error establishing socket error, Internet search for a long time also did not find the answer, later found is not patched. The following is the connection to SQL summary of the following points of attention
1, install SQL Server 200 when try not to select System certification, to choose a hybrid authentication, that is, with SA this user!
2, the data source driver Msbase,mssqlserver,msutil These three packages into your project!
3, you can call the command line "telnet 1433" command to see if your SQL Server port has been opened!
4, check your SQL has not patched, no words to be patched, check the method is run in Query Analyzer:
"SELECT @ @version". If the version number shown below is 8.00.760, you are not installing the SP3 above patch
5, JDBC version must be consistent with the version of SQL Server. If the SP3 SQL is going to sq3 the package, if the SP4 SQL is going to SP4 the package.
6, play the patch when you also need to pay attention to the patch that the file is probably more than 60 m EXE file, you double-click the runtime is not actually installed patches, but only to the designated folder, to really install the directory to run Setup.bat this file.
The above is my summary, if the above work you have done or not, I do not understand, find another master! The main code for connecting to SQL is attached:
String Driver = "Com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=mydata";
String user = "sa";
String password = "123456";
Connection Conn=null;
Statement Stmt=null;
ResultSet Rs=null;
try{
Class.forName (driver);
}catch (ClassNotFoundException e) {
E.printstacktrace ();
}
try{
conn = Drivermanager.getconnection (Url,user,password);
stmt = Conn.createstatement ();
}catch (SQLException e) {
System.out.println (E.tostring ());
}
SYSTEM.OUT.PRINTLN ("Successful database operation, congratulations");