使用 JAVA 代码连接 Azure SQL Database 时产生了 SSL 错误,对于此问题大多数用户都是因为不知如何编写 JDBC 连接字符串而产生的,以下为相关示例代码,供您参考:

 
package sqldbtest;

import java.sql.*;
import com.microsoft.sqlserver.jdbc.*; public class sqldbconn { public static void main(String[] args) {
// TODO Auto-generated method stub
String connectionString =
"jdbc:sqlserver://[server name].database.chinacloudapi.cn:1433;"
+ "database=[database name];"
+ "user==[database name]@ [server name];"
+ "password=xxxxxxxxxxx;"
+ "encrypt=true;"
+ "trustServerCertificate=true;"
+ "hostNameInCertificate=*.database.chinacloudapi.cn;"
+ "loginTimeout=30;"; // Declare the JDBC objects.
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
PreparedStatement prepsInsertPerson = null;
PreparedStatement prepsUpdateAge = null; try {
// INSERT two rows into the table.
// ...
// TRANSACTION and commit for an UPDATE.
// ...
// SELECT rows from the table.
// ...
connection = DriverManager.getConnection(connectionString);
System.out.println("Successful");
System.out.println("1");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// Close the connections after the data has been handled.
if (prepsInsertPerson != null) try { prepsInsertPerson.close(); } catch(Exception e) {}
if (prepsUpdateAge != null) try { prepsUpdateAge.close(); } catch(Exception e) {}
if (resultSet != null) try { resultSet.close(); } catch(Exception e) {}
if (statement != null) try { statement.close(); } catch(Exception e) {}
if (connection != null) try { connection.close(); } catch(Exception e) {}
}
}
}

[AZURE.NOTE] 完善连接字符串 connectionString 中相关参数,根据给出的格式进行修改。

立即访问http://market.azure.cn

最新文章

  1. PD4F将HTML转换为PDF乱码问题
  2. svn忽略eclipse自动生成的文件
  3. centos6.5编译安装git
  4. CUDA学习笔记(一)——CUDA编程模型
  5. BZOJ4377 : [POI2015]Kurs szybkiego czytania
  6. Matlab稀疏矩阵
  7. GuessNumber
  8. Almost Prime
  9. Android中使用HTTP服务
  10. MySQL 讨厌哪种类型的查询
  11. jdk1.7 变更
  12. (转)$.extend()方法和(function($){...})(jQuery)详解
  13. JS中this指向问题相关知识点及解析
  14. java多线程系列8 高级同步工具(2)CountDownLatch
  15. 学习Spring Boot:(二十六)使用 RabbitMQ 消息队列
  16. IE (第二部分) 浏览器 中 关于浏览器模式和文本模式
  17. JAVA设计模式-设计原则
  18. Jade模板引擎使用详解
  19. Solr的入门知识
  20. [置顶] Android异步加载数据库和多线程编程

热门文章

  1. windows install JDK&&JRE
  2. HDU-2553
  3. D - Opponents
  4. Python使用Timer实现验证码功能
  5. [Xcode 实际操作]八、网络与多线程-(25)实现ShareSdk的社会化分享功能
  6. vue2.0.js基础开发使用心得(结合实际项目对数据的增删改查)
  7. Unrecogized font family ‘Ionicons’ 在ios上报错,android正常
  8. web项目数据存入mysql数据库中文乱码问题
  9. STP-5-STP配置及分析
  10. 最短路之SPFA(单源)HDU 2544