Java Connection SQL database (JDBC) Related settings

Source: Internet
Author: User
Tags constant definition sql client

2016-06-14

I. Related settings in SQL Server (for example, SQL Server version 2012)

Establish a server login for SQL Server Authentication

Start the SQL client first, log on to the server as Windows authentication, click Security, and then right click Login--New Login--Enter login name--Select SQL Server Authentication--Enter password-- Don't be sure. Select server role on the left of the current dialog box and tick sysadmin (equivalent to administrator privileges) to restart the database select SQL Server Authentication login and be able to perform some general operations on the tables in the database OK

Ii. Related Settings in eclipse

Preparation: Download jtds-1.3.1-dist (jdbc-sqlserver driver)

Address: Link: http://pan.baidu.com/s/1boW5s7t Password: hkqn

1. First create a new Java project named Jdbctest;

2. Create a new folder under the project named Libs;

3. Save the file just downloaded, unzip it, and pull the Jtds-1.3.1.jar package and x86 or x64 (32-bit and 64-bit according to one of your system) directly into the folder Libs (copy);

4. Right-click Jdbctest-->build path-->configure Build path...--> right now Libraries-->add library...-->jre System Library-->next-->alternate JRE---Select the JDK version (preferably 1.7)-->finish

5. Right-click Jdbctest-->build path-->configure Build path...--> right Libraries-->add jars...--> Find the jdbctest under the Libs Jtds-1.3.1.jar Click OK

6. Now the Libraries page is more than one Jtds-1.3.1.jar the package click on it to the left of the expand button-click native ... --click Edit--> to find the SSO folder under x64 or x86 under Libs under Jdbctest Check-ok

7. Test to build a package under this project Com.cqvie class test copy the following program runs without errors and data is available in the appropriate SQL table.

Package Com.cqvie;

Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.Statement;

public class Test {
Constant definition (usually all caps)
public static final String dbdriver= "Net.sourceforge.jtds.jdbc.Driver";
public static final String Dburl
= "Jdbc:jtds:sqlserver://127.0.0.1:1433;databasename=yinyicao";//ip, port, and database name
public static final String dbuser= "Yych";//Account
public static final String password= "18223779552";//Password
public static void Main (string[] args) throws Exception {
Class.forName (Dbdriver);
Connection cn=drivermanager.getconnection (Dburl,dbuser,password);
Connection cn=drivermanager.getconnection (Dburl);
Statement st=cn.createstatement ();
St.executeupdate ("INSERT into Java_test (SNO,SNAME,SEX,BIRTHDAY,SD)"
+ "VALUES (' 9998 ', ' Yych ', ' 1 ', ' 1996-11-11 ', ' 2 ')");//Operations
Cn.close ();
}

}

Note: If you run a program with an error, open SQL Configuration Manager to check that the relevant settings are correct and that the related service is started. If TCP/IP is started, the port number is not 1433 in the above program and so on. You can check the following steps:

1. Make sure the SQL Sever server is started;


2. Make sure that the 1433 port number is open, confirm the following steps:
(1) Win7 system opens the Control Panel---> program (XP ignores this step)

WIN10 System Control Panel--view mode to categories----programs and features

Again


Click: Programs and Features
On the left, click ' Turn Windows features on or off '

Find ' Telnet client ', tick

(2) Start---> Run---> Input ' cmd ', enter
(3) Enter ' telnet 127.0.0.1 1433 ', with a space between 1 and 1433, if prompted ' unable to open the host connection, the connection failed on port 1433 '. Self-www.baidu.com solution.


3. Open the 1433 port number:
(1) Find the SQL Management Configurator in the Start menu
(2) Bash SQLExpress protocol
(3) Find TCP/IP on the right, right-click Properties
(4) The port number of the Ipall on the IP address is changed to 1433
(5) Right-click on the TCP/IP (3) step to start the service

(6) Start the SQL Sever server

If it can't be solved,-->www.baidu.com is your forever harbor.

Java Connection SQL database (JDBC) Related settings

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.