Java – Run a transactional query in SQL Server on Ubuntu No9

How to execute a transactional query in SQL Server on Ubuntu using Java is shown in this blog. ▼1. How to execute a transactional query in SQL Server on Linux Commit or Rollback by transaction can keep consistency of data when the query fails in the middle of the process. setAutoCommit method of SQLServerConnection class in JDBC Driver can use commit and rollback to implement a transactional query. ▼2. Implement insert query using transaction in SQL Server on Linux 2-1. Creating Java code Transactional insert query will add (6,7) and (7,8) into the table “t1”. after the transaction get started, an insert query is executed and then commit is executed. … Continue reading “Java – Run a transactional query in SQL Server on Ubuntu No9”

Java – Error handling & Retry in SQL Server on Ubuntu No.6

How to implement the error handling and retry with some interval in SQL Server on Ubuntu by Java is shown in this blog. ▼1. An error handling and a retry logic with interval are mandatory When we connect to cloud services, we often experience the intermittent network issue. in this case, an error handling and a retry logic with some interval are mandatory to keep application working on. ▼2. Creating Java code to implement Error handling & Retry logic 2-1. Creating a Java code This Java code implements 3 retries with 30 seconds interval using while after a connection failure. To cause the connection failure, listening port of SQL Server … Continue reading “Java – Error handling & Retry in SQL Server on Ubuntu No.6”

Java -AutoRetry connection by JDBC Driver for SQLServer No53

How to implement auto retry with some internal by Java is shown in this blog. the connection string using Microsoft JDBC Driver for SQL Server “Connection String” has a feature of auto retry with some internal. ▼1. Auto retry with some interval feature of Connection String of Microsoft JDBC Driver for SQL Server (Version 9.4 以上) As the mandatory setting for a cloud service, the following retry with some interval in a connection string can be used after “Microsoft JDBC Driver 9.4 for SQL Server”. ▼2. Writing Java code to implement auto-retry when failing to connect to SQL Server 2.1. Creating a Java code for auto-retry connection This code uses … Continue reading “Java -AutoRetry connection by JDBC Driver for SQLServer No53”

Java – Execute a Select query in SQL Server on Ubuntu No.8

How to run a select query in SQL Server on Ubuntu using Java is shown in this blog. ▼1. Prerequisites Creating a table “t1” in a database “TestDB” and inserting data intho this table are executed by sqlcmd utility. “sa” user is used in this sample. ▼2. Executing a query in SQL Server on Ubuntu by Java 2-1. Creating Java code to execute Select query 1-2. Results of this code Current Timestamps: 2020-05-26 06:52:10.564 [main] INFO ExecuteQSQLSvr – Connect to SQL Server successfully retrieve c1    c2 for t1 table 1    2 2    3 3    4 4    5 5    6 Current Timestamps: 2020-05-26 06:52:11.83 [main] INFO ExecuteQSQLSvr – The connection is … Continue reading “Java – Execute a Select query in SQL Server on Ubuntu No.8”

Java – Put SQL Server select results into a csv file No.70

How to put results of select in SQL Server on Ubuntu into a csv file by Java is shown in this blog. ▼1. Prerequisites There are needed for executing a select query in SQL Server on Ubuntu. 1-1. Installing SQL Server Quickstart: Install SQL Server and create a database on Ubuntu 1-2. Installing Visual Studio Code https://code.visualstudio.com/docs/setup/linux 1-3. Installing Maven Apache Kafka Word Count – Java No.44 “2-3. Installing Apache Maven”Maven – Download Apache Maven 1-4. Generating sample data in SQL Server Python – Creating sample data in SQL Server on Ubuntu No.62 1-5. Executing a select query in SQL Server using Java Java SQL Server on Linux で select … Continue reading “Java – Put SQL Server select results into a csv file No.70”

Java – Update Statistics in SQL Server on Ubuntu No.91

How to update statistics for the table in SQL Server on Ubuntu by Java is shown in this blog. ▼1. The latency of a query execution in SQL Server We often see the latency of a query execution in SQL Server. in this case, Statistics for the table might be old. If the statistics of a table is old, the appropriate query execution plan cannot be generated when running a query. such inefficient query execution plan causes long duration time for the query. The resolution of it is to update statistics for a table. the query “update statistics” and “sp_recompile” to generate a ne query execution plan are implemented by … Continue reading “Java – Update Statistics in SQL Server on Ubuntu No.91”

Java – Creating sample data for SQL Server on Ubuntu No.89

In this blog, how to create sample records for SQL Server on Ubuntu using Java is shown. ▼1. Creating sample data using Java In the past blog, these blogs are shared. they use .sql file to create data by sqlcmd. In this blog, there is the simple way to use Java without sqlcmd to create sample data. ▼2. Prerequisites 2-1. Checking Java – Generating the sample data on SQL Server No.87 to execute below. ▼3. Creating sample data for SQL Server by Java 3-1. Create an Apache Maven project 3-2. Remove the existed both App.java and AppTest.java 3-3. Start Visual Studio Code 3-4. Update pom.xml as below to run query … Continue reading “Java – Creating sample data for SQL Server on Ubuntu No.89”

Java – Calculate the compound interest No.88

How to calculate the compound interest using Java in VS code on Ubuntu is shown in this blog. ▼1. Calculate the compound interest Rob advisor “WealthNavi” and accumulation NISA and private government bounds etc are executed by myself. the compound interest is implemented in these investments. Compound interest is increased by adding interest for the principal and adding interest for the principal + interest next year. the asset will be steadily increased using this process for a long term. Compound interest Wiki In this blog, how to calculate the compound interest by Java is shown. ▼2. Prerequisites 2-1. Installing Visual Studio Code https://code.visualstudio.com/docs/setup/linux 2-2. Installing Maven Apache Kafka Word Count … Continue reading “Java – Calculate the compound interest No.88”

Java – Generating the sample data on SQL Server No.87

In this blog, How to generate the sample data on SQL Server is shown. the key point is to use sqlcmd to run queries in Java. ▼1. Generating the sample data using Java In the pas, how to generate the sample data using python was shown in this blog. Python – Creating sample data in SQL Server on Ubuntu No.62 In the past case, the file which extension is .sql was created and then run this file by sqlcmd. this blog show the way to run query without such .sql file. ▼2. Prerequisites 2-1. Installing SQL Server on Ubuntu Quickstart: Install SQL Server and create a database on Ubuntu 2-2. … Continue reading “Java – Generating the sample data on SQL Server No.87”

Java –Save records for MySQL into Azure Blob Storage No.86 

In this blog, how to save the results of select query for MySQL into Azure Blob Storage by Java. ▼1. Prerequisites 1-1. Install MySQL and create a table with some records Java – Connect to MySQL on Ubuntu and run select query No.80 # Create a table with some records mysql> CREATE DATABASE testdb; mysql> USE testdb; mysql> create table testtbl (c1 int, c2 int); mysql> insert testtbl values(1,1),(2,2),(3,3); mysql> select * from testtbl; +——+——+ | c1 | c2 | +——+——+ | 1 | 1 | | 2 | 2 | | 3 | 3 | +——+——+ 3 rows in set (0.00 sec) ▼2. Save the results of select for … Continue reading “Java –Save records for MySQL into Azure Blob Storage No.86 “