Considerations for JDBC Connection to SQL Server databases and examples of programming applications

Source: Internet
Author: User
Tags microsoft sql server microsoft sql server 2005 connect management studio sql server management sql server management studio strong password firewall

First of all, the installation of the database method in this article is no longer cumbersome, please see my last blog.

http://cq520.iteye.com/admin/blogs/1982097

Note, however, that because computers with Windows operating systems have default SQL Server, you can open your computer to see which SQL Server version is on your computer (locate the Microsoft SQL Server folder in the Start menu, The following version number is the version of SQL Server for this computer.

However, the system's own SQL Server may not have management tools (SQL Server Management Studio, such as My Computer), you can download in Baidu, remember to add your own version number Oh, such as SQL Server Management Studio 2005.

Here's how to use JDBC to connect to a SQL Server database: (in the 2005 version, for example)

1. Close the firewall. Firewall settings can cause you to be unable to connect to the local database, at least for security reasons.

2. Configure the TCP port:

A. Start-> All Programs->microsoft SQL Server 2005-> Configuration Tool->sql Server Configuration Manager->sql Server 2005 Network Configuration->mssqlserver Protocol

B. Enable "TCP/IP" (right click to select "Start") [http://www.colalife.com]

C. Double-click "TCP/IP"-> "IP Address"-> "Ipall"-> "TCP port" to add the default "1433" Port

3. Perimeter application configuration: Microsoft SQL server 2005-> Configuration tool->sql Server perimeter configuration-> Service and connection's perimeter configurator->

① Select sqlexpress->database engine-> remote connection-> local and remote connections-> use TCP/IP and Named pipes

② Select SQL Server browser-> service-> Startup type to "Auto"-> application-> start-> OK

4. Modify the Default logon authentication mode (if installed by default in Windows authentication mode during Setup, the sa login is disabled, and the sa login is disabled even if the authentication mode is changed to SQL Server and Windows authentication mode). So you need to enable the SA login account):

① in the Object Explorer of SQL Server Management Studio, security-> login-> Right-click the "sa"-> attribute->

General-> set the password and confirmation password for the login SA to strong password-> status-> login-> enable-> OK

② in the Object Explorer of SQL Server Management Studio, right-click the server-> property-> security-> Server Authentication-> Choose SQL Server and Windows Authentication mode-> determine- > Determine

5. Create a new database (such as "MyTest") in SQL Server Management Studio that can be attached directly to the current SQL Server database server without creating a new one, if the test program has a database file, in SQL Server Management Studio's Object Explorer right-click the server-> reboot-> is

6. Run the downloaded JDBC file "Sqljdbc_1.2.2828.100_chs.exe", (already in the attachment to everyone), extract to the "C:\Program files" folder; [http://www.colalife.com]

Setting the classpath to include Sqljdbc.jar files (which can also be added to the system environment variable) suggests finding Sqljdbc.jar from the unpacked folder and copying it to your favorite Jar folder and finding it handy.

7. JDBC Connection settings and testing in eclipse3.2/3.3 or myeclipse6.0/6.5

1, open eclipse3.2/3.3 or myeclipse6.0/6.5, new Java project, project name is test

2, select "Window" → "Preferences" → "Java" → "Inst alled jres", select the installed JRE, click "Edit ..." → "add External JARs", find Sqljdbc.jar and add- >ok

3, "window"-> "Open Perspective"-> "MyEclipse Database Explorer"-> (left) "DB Browser" right Key "New"-> fill in the link properties driver Name,url is: jdbc:sqlserver://localhost:1433;databasename=mytest,user name:sa,password: password. And then add JARs to the driver JARs dot adding sqljdbc.jar, dot and test

Driver test, check the save password saved password, click Finish--that is, complete the connection database configuration in DB Browser.

By the end of this step, our configuration work has been basically completed, followed by a concrete example of database programming. It should be noted that, as I mentioned above, to do database programming, at least have a database (Ching), but also some basic database operations, which have learned the database course you should have no problem, if you have not learned the database course, it does not matter, You can take the time to look at some of the database's simple operations, which are easy to find in relevant textbooks.

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.