All Products
Search
Document Center

ApsaraDB RDS:How does Java connect to RDS SQL Server?

Last Updated:Nov 23, 2020

Disclaimer: This article may contain information about third-party products. Such information is for reference only. Alibaba Cloud does not make any guarantee, express or implied, with respect to the performance and reliability of third-party products, as well as potential impacts of operations on the products.

Introduction

This article describes how to use Java to connect to RDS SQL Server.

Background

Alibaba Cloud reminds you that:

  • Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
  • You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.
  • If you have authorized or submitted security information such as the logon account and password in the Alibaba Cloud Management console, we recommend that you modify such information in a timely manner.
  1. JDK 1.7 or later is required. For more information, see the Microsoft website and download the JAR package.
  2. The code snippets for importing sqljdbc42.jar files into project are as follows:
     String userName = "XXX";
     String userPwd = "XXX";
     String url="jdbc:sqlserver://rds.sqlserver.rds.aliyuncs.com:3433;DatabaseName=dbtest";
     java.sql.Connection  dbConn = DriverManager.getConnection(url, userName, userPwd);
     Object sta = dbConn.createStatement();
     String sql = "create table student"+ "(id int , name varchar(10))";
     int row = ((Statement) sta).executeUpdate(sql);
     System.out.println("successfully");

Application scope

  • ApsaraDB RDS for SQL Server