-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASA_Client.java
More file actions
88 lines (72 loc) · 2.77 KB
/
ASA_Client.java
File metadata and controls
88 lines (72 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package AsaClient;
//SQL
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//Microsoft JDBC Driver
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
//Java Utilities
import java.util.Properties;
public class AsaClientMain {
public static void main(String[] args) {
// Connecting to Azure Synapse SQL Server using JDBC
//https://docs.microsoft.com/en-us/sql/connect/jdbc/parsing-the-results?view=sql-server-ver15
String server = "svrName.database.windows.net";
String port = "1433";
String dbName = "dwDbName";
String user = "userName";
String pass = "PassWord";
String connectionUrl = "jdbc:sqlserver://" + server + ":" + port + ";database=" + dbName + ";user=" + user+";password=" + pass;
//Establish and reuse the connection
Connection con = null;
try {
con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
e.printStackTrace();
}
// Try a simple select query
try (Statement stmt = con.createStatement();) {
String SQL = "SELECT TOP 10 * FROM dbo.DimAccount";
ResultSet rs = stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println("Hello");
System.out.println(rs.getString("AccountKey") + " " + rs.getString("AccountType") + " " + rs.getString("ValueType"));
}
stmt.close();
}
// Handle any errors that may have occurred.
catch (SQLException e) {
e.printStackTrace();
}
// Try update with join
try (Statement stmt = con.createStatement();) {
String SQL = new StringBuilder()
.append("update [dbo].[DimAccountTar] \n")
.append("set dbo.DimAccountTar.CustomMembers = stg.CustomMembers, \n")
.append("dbo.DimAccountTar.CustomMemberOptions = stg.CustomMemberOptions \n")
.append("From [dbo].[DimAccountTar] \n")
.append("Join [dbo].[DimAccountStg] stg \n")
.append("on dbo.DimAccountTar.AccountKey = stg.AccountKey \n")
.toString();
System.out.println(SQL);
stmt.executeUpdate(SQL);
//stmt.executeQuery(SQL);
stmt.close();
}
// Handle any errors that may have occurred.
catch (SQLException e) {
e.printStackTrace();
}
// Now close the connection
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Done");
}
}