mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
The Java samples have quite a lot of room for improvement.
I changed the following:
- make the code compile
- update the readme to point to the latest driver
- remove one leading tab from every line
- remove redundant imports
- use Java 7 try-with-resources
- release database objects as early as possible
- propagate exceptions
- use bind parameters to avoid SQL-injection vulnerabilities when the
code is copy and pasted and adjusted
- I had to guess on some of the parameter types since I didn't have a
schema. I had a look at ql_in-memory_oltp_sample.sql. Executable
samples with a continuous integration build would be a nice future
improvement.
Connect to SQL Database by using Java with JDBC on Windows
[Java code sample] (sample_java.java) that you can use to connect to Azure SQL Database. The Java sample relies on the Java Development Kit (JDK) version 8. The sample connects to an Azure SQL Database by using the JDBC driver.
Requirements
- Microsoft JDBC Driver for SQL Server - SQL JDBC 6.0. - Download the latest JDBC Driver 6.0 Package sqljdbc_6.0.7507.100_enu.exe OR sqljdbc_6.0.7507.100_enu.tar.gz - For guidance on which jar file to use based on your Java version, please see the System Requirements for the JDBC Driver
- Any operating system platform that runs Java Development Kit 8.
- An existing database on SQL Azure. See the Get Started topic to learn how to create a sample database and retrieve your connection string.
Create a database, retrieve your connection string
The Java sample relies on the AdventureWorks sample database. If you do not already have AdventureWorks, you can see how to create it at the following topic: Create your first Azure SQL Database