Error while performing database login with the SQLJDBC driver:unable to create connection. Check your URL.

Source: Internet
Author: User
Tags auth

Download the JDBC driver package SQLJDBC4 from Microsoft Official website, run Sqljdbc_4.0.2206.100_chs.exe, unzip the driver package to the Microsoft JDBC Driver 4.0 for SQL Server folder, There are two folders x64 and x86 under Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\chs\auth, and there is a sqljdbc_ under both folders Auth.dll file, copy the Sqljdbc_auth.dll file inside the x64 folder to Windows\System32, copy x86 under Sqljdbc_auth.dll folder to Windows\SysWOW64, Why did you do that?

Here a little science, under the Windows directory of 32-bit system is only the System32 folder does not have sysWOW64 folder, System32 below the main storage of 32-bit program to run the library files, to create a 32-bit program running environment, But the 64-bit system under the System32 is stored in the 64-bit program to run the required library files, to create a 64-bit program running environment, in order to be compatible with 32-bit programs, Microsoft in the Windows directory to add a sysWOW64 folder, The SysWOW64 folder contains files that create a 32-bit program running environment. Therefore, in my computer, the above x64 folder under the Sqljdbc_auth.dll to be placed under System32, and x86 folder Sqljdbc_auth.dll should be placed in the SysWOW64 folder.

Then, create the system environment variable classpath, the Sqljdbc4.jar is located in the path added to the value of Classpath, but later proved that this step in this practice has no effect, belongs to the extra step, the follow-up practice will not be used to know.

Start MyEclipse, open the db browser window in window-preferences-myeclipse-database drivers

Right-click in the blank of the DB browser window circled in the Red box above and select New to open the following window

Driver template selects Microsoft SQL Server,

Driver name fill in,

Connection url:jdbc:microsoft:sqlserver://localhost:1433

Username:sa

Password fill in your own sa account password

Then click on the "Add JARS" button to add Sqljdbc4.jar,

The following driver classname will be automatically generated after adding Sqljdbc4.jar

Fill it out as you would.

Then you can test the drive line, click the test Driver button, enter the password

OK, but the prompt error, the error is as follows:

Above said is the URL problem, I Baidu a bit this problem, found that is really a URL problem, the above URL should be

jdbc:sqlserver://localhost:1433

As for the reason, as if to say what again, I do not remember.

After the change, at Test Driver, it worked.

Then you can order the finish. After the completion of the DB browser there is a sqljdbc, I fill in the above driver name is SQLJDBC, so there is a sqljdbc.

Well, this is according to the previous configuration of the MySQL database step configuration, and later proved that this step seems to be actually redundant, in this practice did not play a practical role.

Getting ready to work here is basically done, and the following begins to build the project to write code.

Start MyEclipse, create a new Web project, right-click the project name, select Buildpath-add External Archives, select Add Sqljdbc4.jar

Then the referenced libraries directory will appear Sqljdbc4.jar, this is the process of importing the SQLJDBC driver package, but later I found that this step is redundant, also did not work.

Here, I've done three extra things, the first time is to add the Classpat system H environment variable, the second is to add the Sqljdbc driver interactively in MyEclipse, and the third is to import the SQLJDBC package.

Small white struggle history is full of hardships!

Then it's the code.

Add SQL Package reference to index.jsp, pageencoding set to "Utf-8"

Add code inside the body

<%

try{

Connection Con;

Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");

Con = Drivermanager.getconnection ("Jdbc:sqlserver://localhost:1433;databasename=master", "sa", "123456");

System.out.println ("Step1 goes Well");

}

catch (Exception e) {

System.out.println ("Step1 down");

E.printstacktrace ();

}

%>

Save, deploy to tomcat7.x, then launch tomcat7.x, launch MyEclipse Browser, browse our index.jsp page, find errors, Report classnotfoundexception.

After a lot of detours (these detours are meaningless detours are not recorded), finally determined that the Sqljdbc4.jar should be copied to the Tomcat path under the WEPAAP project path under the Web-inf\lib.

Then reboot tomcat to access the index.jsp, prompting for a successful connection.

Then is the new project, delete the previously added sqljdbc driver, delete the CLASSPATH environment variable, this time also does not add External Archives, write code directly, copy Sqljdbc4.jar to the above said Web-inf\lib directory, test connection , the connection was successful, indicating that the previous three steps are useless.

Error while performing database login with the SQLJDBC driver:unable to create connection. Check your URL.

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.