1. Some tips on using Java to connect SQL Server 2000

Source: Internet
Author: User
Tags stmt server port

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");



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.