From f5c4e3af74da4a636e558615a20ba0d366698ad5 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Sun, 20 Jan 2019 00:08:52 -0500 Subject: [PATCH 01/10] BAEL-2339 || ResultSet Demo BAEL-2339 || ResultSet Demo --- .../main/java/com/baeldung/jdbc/Employee.java | 6 +- .../com/baeldung/jdbc/ResultSetLiveTest.java | 325 ++++++++++++++++++ 2 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java index 749855ca3b..8f3fce0378 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java @@ -47,5 +47,9 @@ public class Employee { public void setPosition(String position) { this.position = position; } - + + @Override + public boolean equals(Object obj) { + return this.getId() == ((Employee) obj).getId(); + } } diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java new file mode 100644 index 0000000000..369d5e9222 --- /dev/null +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -0,0 +1,325 @@ +package com.baeldung.jdbc; + +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ResultSetLiveTest { + + private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); + + private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); + + private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); + + private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); + + private final int rowCount = 2; + + private static Connection dbConnection; + + @BeforeClass + public static void setup() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + try (Statement stmt = dbConnection.createStatement()) { + stmt.execute(tableSql); + try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { + pstmt.executeUpdate(); + } + } + } + + @Test + public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + + assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); + } + + @Test + public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Integer empId = rs.getInt(1); + String name = rs.getString(2); + String position = rs.getString(3); + Double salary = rs.getDouble(4); + employee = new Employee(empId, name, salary, position); + } + } + + assertEquals("Employee information retreived by column ids.", employee, expectedEmployee1); + } + + @Test + public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { + int rowCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.moveToInsertRow(); + rs.updateString("name", "Venkat"); + rs.updateString("position", "DBA"); + rs.updateDouble("salary", 925.0); + rs.insertRow(); + rs.moveToCurrentRow(); + rs.last(); + rowCount = rs.getRow(); + } + + assertEquals("Row Count after inserting a row", rowCount, 2); + } + + private Employee populateResultSet(ResultSet rs) throws SQLException { + Employee employee; + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + return employee; + } + + @Test + public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Num of rows", numOfRows, rowCount); + } + + @Test + public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(2); + secondEmployee = populateResultSet(rs); + } + + assertEquals("Absolute navigation", secondEmployee, expectedEmployee2); + } + + @Test + public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + secondEmployee = populateResultSet(rs); + } + + assertEquals("Using Last", secondEmployee, expectedEmployee2); + } + + @Test + public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { + Employee firstEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.beforeFirst(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.first(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.afterLast(); + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + while (rs.previous()) { + firstEmployee = populateResultSet(rs); + } + } + + assertEquals("Several Navigation Options", firstEmployee, updatedEmployee1); + } + + @Test + public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { + int numOfRows = 0; + dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Inserted using close cursor after commit", numOfRows, 3); + } + + @Test + public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { + int numOfRows = 0; + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Inserted using hold cursor after commit", numOfRows, 4); + } + + @Test + public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(3); + rs.deleteRow(); + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Deleted row", numOfRows, 3); + } + + @Test + public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + rs.updateDouble("salary", 1100.0); + rs.updateRow(); + rs.refreshRow(); + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + + assertEquals("Employee information updated successfully.", employee, updatedEmployee1); + } + + @Test + public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { + DatabaseMetaData dbmd = dbConnection.getMetaData(); + boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); + boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); + boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); + boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + int rsHoldability = dbmd.getResultSetHoldability(); + + assertEquals("checking scroll sensitivity and concur updates : ", concurrency4TypeScrollInSensitiveNConcurUpdatable, true); + } + + @Test + public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { + int columnCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + ResultSetMetaData metaData = rs.getMetaData(); + columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String catalogName = metaData.getCatalogName(i); + String className = metaData.getColumnClassName(i); + String label = metaData.getColumnLabel(i); + String name = metaData.getColumnName(i); + String typeName = metaData.getColumnTypeName(i); + Integer type = metaData.getColumnType(i); + String tableName = metaData.getTableName(i); + String schemaName = metaData.getSchemaName(i); + boolean isAutoIncrement = metaData.isAutoIncrement(i); + boolean isCaseSensitive = metaData.isCaseSensitive(i); + boolean isCurrency = metaData.isCurrency(i); + boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); + boolean isReadOnly = metaData.isReadOnly(i); + boolean isSearchable = metaData.isSearchable(i); + boolean isReadable = metaData.isReadOnly(i); + boolean isSigned = metaData.isSigned(i); + boolean isWritable = metaData.isWritable(i); + int nullable = metaData.isNullable(i); + } + } + + assertEquals("column count", columnCount, 4); + } + + @Test + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + PreparedStatement pstmt = null; + ResultSet rs = null; + List listOfEmployees = new ArrayList(); + try { + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(2); + rs = pstmt.executeQuery(); + rs.setFetchSize(1); + while (rs.next()) { + Employee employee = populateResultSet(rs); + listOfEmployees.add(employee); + } + } catch (Exception e) { + throw e; + } finally { + if (rs != null) + rs.close(); + if (pstmt != null) + pstmt.close(); + } + + assertEquals(listOfEmployees.size(), 3); + } + + @AfterClass + public static void closeConnection() throws SQLException { + PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + deleteStmt.execute(); + dbConnection.close(); + } +} From eb8f0cf66c5464eb6664731477305d9ea16ffd81 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Tue, 22 Jan 2019 02:20:08 -0500 Subject: [PATCH 02/10] Fixed unit tests and equals method for ResultSetLiveTest --- .../main/java/com/baeldung/jdbc/Employee.java | 98 ++-- .../com/baeldung/jdbc/ResultSetLiveTest.java | 551 +++++++++--------- 2 files changed, 344 insertions(+), 305 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java index 8f3fce0378..88af4902b5 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java @@ -1,55 +1,71 @@ package com.baeldung.jdbc; +import java.util.Objects; + public class Employee { - private int id; - private String name; - private String position; - private double salary; + private int id; + private String name; + private String position; + private double salary; - public Employee() { - } + public Employee() { + } - public Employee(int id, String name, double salary, String position) { - this.id = id; - this.name = name; - this.salary = salary; - this.position = position; - } + public Employee(int id, String name, double salary, String position) { + this.id = id; + this.name = name; + this.salary = salary; + this.position = position; + } - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public double getSalary() { - return salary; - } + public double getSalary() { + return salary; + } - public void setSalary(double salary) { - this.salary = salary; - } + public void setSalary(double salary) { + this.salary = salary; + } - public String getPosition() { - return position; - } + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, position, salary); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Employee other = (Employee) obj; + return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) + && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary); + } - public void setPosition(String position) { - this.position = position; - } - - @Override - public boolean equals(Object obj) { - return this.getId() == ((Employee) obj).getId(); - } } diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 369d5e9222..553c7f9919 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -23,303 +23,326 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResultSetLiveTest { - private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); + private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); - private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); + private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); - private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); + private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); - private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); + private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); - private final int rowCount = 2; + private final int rowCount = 2; - private static Connection dbConnection; + private static Connection dbConnection; - @BeforeClass - public static void setup() throws ClassNotFoundException, SQLException { - Class.forName("com.mysql.cj.jdbc.Driver"); - dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); - String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; - try (Statement stmt = dbConnection.createStatement()) { - stmt.execute(tableSql); - try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { - pstmt.executeUpdate(); - } - } - } + @BeforeClass + public static void setup() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", + "user1", "pass"); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + try (Statement stmt = dbConnection.createStatement()) { + stmt.execute(tableSql); + try (PreparedStatement pstmt = dbConnection.prepareStatement( + "INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { + pstmt.executeUpdate(); + } + } + } - @Test - public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); + ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); - } + assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Integer empId = rs.getInt(1); - String name = rs.getString(2); - String position = rs.getString(3); - Double salary = rs.getDouble(4); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); + ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Integer empId = rs.getInt(1); + String name = rs.getString(2); + String position = rs.getString(3); + Double salary = rs.getDouble(4); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column ids.", employee, expectedEmployee1); - } + assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { - int rowCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.moveToInsertRow(); - rs.updateString("name", "Venkat"); - rs.updateString("position", "DBA"); - rs.updateDouble("salary", 925.0); - rs.insertRow(); - rs.moveToCurrentRow(); - rs.last(); - rowCount = rs.getRow(); - } + @Test + public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { + int rowCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.moveToInsertRow(); + rs.updateString("name", "Venkat"); + rs.updateString("position", "DBA"); + rs.updateDouble("salary", 925.0); + rs.insertRow(); + rs.moveToCurrentRow(); + rs.last(); + rowCount = rs.getRow(); + } - assertEquals("Row Count after inserting a row", rowCount, 2); - } + assertEquals("Row Count after inserting a row", 2, rowCount); + } - private Employee populateResultSet(ResultSet rs) throws SQLException { - Employee employee; - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - return employee; - } + private Employee populateResultSet(ResultSet rs) throws SQLException { + Employee employee; + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + return employee; + } - @Test - public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Num of rows", numOfRows, rowCount); - } + assertEquals("Num of rows", rowCount, numOfRows); + } - @Test - public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(2); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(2); + secondEmployee = populateResultSet(rs); + } - assertEquals("Absolute navigation", secondEmployee, expectedEmployee2); - } + assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + secondEmployee = populateResultSet(rs); + } - assertEquals("Using Last", secondEmployee, expectedEmployee2); - } + assertEquals("Using Last", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { - Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.beforeFirst(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.first(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.afterLast(); - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - while (rs.previous()) { - firstEmployee = populateResultSet(rs); - } - } + @Test + public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { + Employee firstEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.beforeFirst(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.first(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.afterLast(); + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + while (rs.previous()) { + firstEmployee = populateResultSet(rs); + } + } - assertEquals("Several Navigation Options", firstEmployee, updatedEmployee1); - } + assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); + } - @Test - public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { - int numOfRows = 0; - dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { + int numOfRows = 0; + dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, + ResultSet.CLOSE_CURSORS_AT_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using close cursor after commit", numOfRows, 3); - } + assertEquals("Inserted using close cursor after commit", 3, numOfRows); + } - @Test - public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { - int numOfRows = 0; - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { + int numOfRows = 0; + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, + ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using hold cursor after commit", numOfRows, 4); - } + assertEquals("Inserted using hold cursor after commit", 4, numOfRows); + } - @Test - public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(3); - rs.deleteRow(); - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(3); + rs.deleteRow(); + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Deleted row", numOfRows, 3); - } + assertEquals("Deleted row", 3, numOfRows); + } - @Test - public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - rs.updateDouble("salary", 1100.0); - rs.updateRow(); - rs.refreshRow(); - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + rs.updateDouble("salary", 1100.0); + rs.updateRow(); + rs.refreshRow(); + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information updated successfully.", employee, updatedEmployee1); - } + assertEquals("Employee information updated successfully.", updatedEmployee1, employee); + } - @Test - public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { - DatabaseMetaData dbmd = dbConnection.getMetaData(); - boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); - boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); - boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); - boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - int rsHoldability = dbmd.getResultSetHoldability(); + @Test + public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { + DatabaseMetaData dbmd = dbConnection.getMetaData(); + boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); + boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); + boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); + boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + int rsHoldability = dbmd.getResultSetHoldability(); - assertEquals("checking scroll sensitivity and concur updates : ", concurrency4TypeScrollInSensitiveNConcurUpdatable, true); - } + assertEquals("checking scroll sensitivity and concur updates : ", true, + concurrency4TypeScrollInSensitiveNConcurUpdatable); + } - @Test - public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { - int columnCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - ResultSetMetaData metaData = rs.getMetaData(); - columnCount = metaData.getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - String catalogName = metaData.getCatalogName(i); - String className = metaData.getColumnClassName(i); - String label = metaData.getColumnLabel(i); - String name = metaData.getColumnName(i); - String typeName = metaData.getColumnTypeName(i); - Integer type = metaData.getColumnType(i); - String tableName = metaData.getTableName(i); - String schemaName = metaData.getSchemaName(i); - boolean isAutoIncrement = metaData.isAutoIncrement(i); - boolean isCaseSensitive = metaData.isCaseSensitive(i); - boolean isCurrency = metaData.isCurrency(i); - boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); - boolean isReadOnly = metaData.isReadOnly(i); - boolean isSearchable = metaData.isSearchable(i); - boolean isReadable = metaData.isReadOnly(i); - boolean isSigned = metaData.isSigned(i); - boolean isWritable = metaData.isWritable(i); - int nullable = metaData.isNullable(i); - } - } + @Test + public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { + int columnCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + ResultSetMetaData metaData = rs.getMetaData(); + columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String catalogName = metaData.getCatalogName(i); + String className = metaData.getColumnClassName(i); + String label = metaData.getColumnLabel(i); + String name = metaData.getColumnName(i); + String typeName = metaData.getColumnTypeName(i); + Integer type = metaData.getColumnType(i); + String tableName = metaData.getTableName(i); + String schemaName = metaData.getSchemaName(i); + boolean isAutoIncrement = metaData.isAutoIncrement(i); + boolean isCaseSensitive = metaData.isCaseSensitive(i); + boolean isCurrency = metaData.isCurrency(i); + boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); + boolean isReadOnly = metaData.isReadOnly(i); + boolean isSearchable = metaData.isSearchable(i); + boolean isReadable = metaData.isReadOnly(i); + boolean isSigned = metaData.isSigned(i); + boolean isWritable = metaData.isWritable(i); + int nullable = metaData.isNullable(i); + } + } - assertEquals("column count", columnCount, 4); - } + assertEquals("column count", 4, columnCount); + } - @Test - public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { - PreparedStatement pstmt = null; - ResultSet rs = null; - List listOfEmployees = new ArrayList(); - try { - pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - pstmt.setFetchSize(2); - rs = pstmt.executeQuery(); - rs.setFetchSize(1); - while (rs.next()) { - Employee employee = populateResultSet(rs); - listOfEmployees.add(employee); - } - } catch (Exception e) { - throw e; - } finally { - if (rs != null) - rs.close(); - if (pstmt != null) - pstmt.close(); - } - - assertEquals(listOfEmployees.size(), 3); - } + @Test + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + PreparedStatement pstmt = null; + ResultSet rs = null; + List listOfEmployees = new ArrayList(); + try { + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(2); + rs = pstmt.executeQuery(); + rs.setFetchSize(1); + while (rs.next()) { + Employee employee = populateResultSet(rs); + listOfEmployees.add(employee); + } + } catch (Exception e) { + throw e; + } finally { + if (rs != null) + rs.close(); + if (pstmt != null) + pstmt.close(); + } - @AfterClass - public static void closeConnection() throws SQLException { - PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - deleteStmt.execute(); - dbConnection.close(); - } + assertEquals(3, listOfEmployees.size()); + } + + @AfterClass + public static void closeConnection() throws SQLException { + PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", + ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + deleteStmt.execute(); + dbConnection.close(); + } } From 48bad8243930c53eb936e1bc37b2126a10302ea2 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Thu, 24 Jan 2019 13:16:56 -0500 Subject: [PATCH 03/10] Fixed issues with adding the 2nd record --- .../com/baeldung/jdbc/ResultSetLiveTest.java | 554 +++++++++--------- 1 file changed, 268 insertions(+), 286 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 553c7f9919..64d64e76f2 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -20,329 +20,311 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import junit.framework.Assert; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResultSetLiveTest { - private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); + private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); - private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); + private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); - private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); + private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); - private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); + private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); - private final int rowCount = 2; + private final int rowCount = 2; - private static Connection dbConnection; + private static Connection dbConnection; - @BeforeClass - public static void setup() throws ClassNotFoundException, SQLException { - Class.forName("com.mysql.cj.jdbc.Driver"); - dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", - "user1", "pass"); - String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; - try (Statement stmt = dbConnection.createStatement()) { - stmt.execute(tableSql); - try (PreparedStatement pstmt = dbConnection.prepareStatement( - "INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { - pstmt.executeUpdate(); - } - } - } + @BeforeClass + public static void setup() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + try (Statement stmt = dbConnection.createStatement()) { + stmt.execute(tableSql); + try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { + pstmt.executeUpdate(); + } + } + } - @Test - public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); - ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionA_whenRetreiveByColumnNames_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); - } + assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); - ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Integer empId = rs.getInt(1); - String name = rs.getString(2); - String position = rs.getString(3); - Double salary = rs.getDouble(4); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionB_whenRetreiveByColumnIds_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Integer empId = rs.getInt(1); + String name = rs.getString(2); + String position = rs.getString(3); + Double salary = rs.getDouble(4); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); - } + assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { - int rowCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.moveToInsertRow(); - rs.updateString("name", "Venkat"); - rs.updateString("position", "DBA"); - rs.updateDouble("salary", 925.0); - rs.insertRow(); - rs.moveToCurrentRow(); - rs.last(); - rowCount = rs.getRow(); - } + @Test + public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { + int rowCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.moveToInsertRow(); + rs.updateString("name", "Chris"); + rs.updateString("position", "DBA"); + rs.updateDouble("salary", 925.0); + rs.insertRow(); + rs.moveToCurrentRow(); + rs.last(); + rowCount = rs.getRow(); + } - assertEquals("Row Count after inserting a row", 2, rowCount); - } + assertEquals("Row Count after inserting a row", 2, rowCount); + } - private Employee populateResultSet(ResultSet rs) throws SQLException { - Employee employee; - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - return employee; - } + private Employee populateResultSet(ResultSet rs) throws SQLException { + Employee employee; + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + return employee; + } - @Test - public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Num of rows", rowCount, numOfRows); - } + assertEquals("Num of rows", rowCount, numOfRows); + } - @Test - public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(2); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(2); + secondEmployee = populateResultSet(rs); + } - assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); - } + assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + secondEmployee = populateResultSet(rs); + } - assertEquals("Using Last", expectedEmployee2, secondEmployee); - } + assertEquals("Using Last", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { - Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.beforeFirst(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.first(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.afterLast(); - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - while (rs.previous()) { - firstEmployee = populateResultSet(rs); - } - } + @Test + public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { + Employee firstEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.beforeFirst(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.first(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.afterLast(); + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + while (rs.previous()) { + firstEmployee = populateResultSet(rs); + } + } - assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); - } + assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); + } - @Test - public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { - int numOfRows = 0; - dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, - ResultSet.CLOSE_CURSORS_AT_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { + int numOfRows = 0; + dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using close cursor after commit", 3, numOfRows); - } + assertEquals("Inserted using close cursor after commit", 3, numOfRows); + } - @Test - public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { - int numOfRows = 0; - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, - ResultSet.HOLD_CURSORS_OVER_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { + int numOfRows = 0; + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using hold cursor after commit", 4, numOfRows); - } + assertEquals("Inserted using hold cursor after commit", 4, numOfRows); + } - @Test - public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(3); - rs.deleteRow(); - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(3); + rs.deleteRow(); + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Deleted row", 3, numOfRows); - } + assertEquals("Deleted row", 3, numOfRows); + } - @Test - public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - rs.updateDouble("salary", 1100.0); - rs.updateRow(); - rs.refreshRow(); - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { - assertEquals("Employee information updated successfully.", updatedEmployee1, employee); - } + Assert.assertEquals(1000.0, rs.getDouble("salary")); - @Test - public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { - DatabaseMetaData dbmd = dbConnection.getMetaData(); - boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); - boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); - boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); - boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - int rsHoldability = dbmd.getResultSetHoldability(); + rs.updateDouble("salary", 1100.0); + rs.updateRow(); - assertEquals("checking scroll sensitivity and concur updates : ", true, - concurrency4TypeScrollInSensitiveNConcurUpdatable); - } + Assert.assertEquals(1100.0, rs.getDouble("salary")); - @Test - public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { - int columnCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - ResultSetMetaData metaData = rs.getMetaData(); - columnCount = metaData.getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - String catalogName = metaData.getCatalogName(i); - String className = metaData.getColumnClassName(i); - String label = metaData.getColumnLabel(i); - String name = metaData.getColumnName(i); - String typeName = metaData.getColumnTypeName(i); - Integer type = metaData.getColumnType(i); - String tableName = metaData.getTableName(i); - String schemaName = metaData.getSchemaName(i); - boolean isAutoIncrement = metaData.isAutoIncrement(i); - boolean isCaseSensitive = metaData.isCaseSensitive(i); - boolean isCurrency = metaData.isCurrency(i); - boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); - boolean isReadOnly = metaData.isReadOnly(i); - boolean isSearchable = metaData.isSearchable(i); - boolean isReadable = metaData.isReadOnly(i); - boolean isSigned = metaData.isSigned(i); - boolean isWritable = metaData.isWritable(i); - int nullable = metaData.isNullable(i); - } - } + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + } - assertEquals("column count", 4, columnCount); - } + @Test + public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { + DatabaseMetaData dbmd = dbConnection.getMetaData(); + boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); + boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); + boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); + boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + int rsHoldability = dbmd.getResultSetHoldability(); - @Test - public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { - PreparedStatement pstmt = null; - ResultSet rs = null; - List listOfEmployees = new ArrayList(); - try { - pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY); - pstmt.setFetchSize(2); - rs = pstmt.executeQuery(); - rs.setFetchSize(1); - while (rs.next()) { - Employee employee = populateResultSet(rs); - listOfEmployees.add(employee); - } - } catch (Exception e) { - throw e; - } finally { - if (rs != null) - rs.close(); - if (pstmt != null) - pstmt.close(); - } + assertEquals("checking scroll sensitivity and concur updates : ", true, concurrency4TypeScrollInSensitiveNConcurUpdatable); + } - assertEquals(3, listOfEmployees.size()); - } + @Test + public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { + int columnCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + ResultSetMetaData metaData = rs.getMetaData(); + columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String catalogName = metaData.getCatalogName(i); + String className = metaData.getColumnClassName(i); + String label = metaData.getColumnLabel(i); + String name = metaData.getColumnName(i); + String typeName = metaData.getColumnTypeName(i); + Integer type = metaData.getColumnType(i); + String tableName = metaData.getTableName(i); + String schemaName = metaData.getSchemaName(i); + boolean isAutoIncrement = metaData.isAutoIncrement(i); + boolean isCaseSensitive = metaData.isCaseSensitive(i); + boolean isCurrency = metaData.isCurrency(i); + boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); + boolean isReadOnly = metaData.isReadOnly(i); + boolean isSearchable = metaData.isSearchable(i); + boolean isReadable = metaData.isReadOnly(i); + boolean isSigned = metaData.isSigned(i); + boolean isWritable = metaData.isWritable(i); + int nullable = metaData.isNullable(i); + } + } - @AfterClass - public static void closeConnection() throws SQLException { - PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", - ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - deleteStmt.execute(); - dbConnection.close(); - } + assertEquals("column count", 4, columnCount); + } + + @Test + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + PreparedStatement pstmt = null; + ResultSet rs = null; + List listOfEmployees = new ArrayList(); + try { + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(2); + rs = pstmt.executeQuery(); + rs.setFetchSize(1); + while (rs.next()) { + Employee employee = populateResultSet(rs); + listOfEmployees.add(employee); + } + } catch (Exception e) { + throw e; + } finally { + if (rs != null) + rs.close(); + if (pstmt != null) + pstmt.close(); + } + + assertEquals(3, listOfEmployees.size()); + } + + @AfterClass + public static void closeConnection() throws SQLException { + PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + deleteStmt.execute(); + dbConnection.close(); + } } From d9b88ed303d95a2d2ed72c34c445f7a9f88181a4 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Thu, 24 Jan 2019 15:03:42 -0500 Subject: [PATCH 04/10] Fixed some resultset creation --- .../src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 64d64e76f2..ef01382e2c 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -112,7 +112,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } @@ -123,7 +123,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { rs.absolute(2); secondEmployee = populateResultSet(rs); } @@ -145,7 +145,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { Employee employee = populateResultSet(rs); } From 2fadf8b5a0cda9dedf9f9e40e430a825257d9832 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Thu, 24 Jan 2019 15:09:02 -0500 Subject: [PATCH 05/10] d --- .../src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index ef01382e2c..7f714a9b32 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -79,7 +79,7 @@ public class ResultSetLiveTest { } } - assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); + assertEquals("Employee information retreived by column ids:", expectedEmployee1, employee); } @Test From 474a3675f1575b244f15d1a812a94aa4d4ae52f3 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Fri, 25 Jan 2019 03:06:50 -0500 Subject: [PATCH 06/10] Fixed the name of the fetch example --- .../com/baeldung/jdbc/ResultSetLiveTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 7f714a9b32..2762aeda5e 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -79,7 +79,7 @@ public class ResultSetLiveTest { } } - assertEquals("Employee information retreived by column ids:", expectedEmployee1, employee); + assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); } @Test @@ -112,7 +112,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } @@ -123,7 +123,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.absolute(2); secondEmployee = populateResultSet(rs); } @@ -145,7 +145,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { Employee employee = populateResultSet(rs); } @@ -195,6 +195,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { int numOfRows = 0; + dbConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { dbConnection.setAutoCommit(false); pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); @@ -211,15 +212,16 @@ public class ResultSetLiveTest { } @Test - public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { int numOfRows = 0; try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.absolute(3); rs.deleteRow(); + } + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } - assertEquals("Deleted row", 3, numOfRows); } @@ -296,13 +298,13 @@ public class ResultSetLiveTest { } @Test - public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + public void givenDbConnectionL_whenFetch_thenCorrect() throws SQLException { PreparedStatement pstmt = null; ResultSet rs = null; List listOfEmployees = new ArrayList(); try { - pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - pstmt.setFetchSize(2); + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + pstmt.setFetchSize(1); rs = pstmt.executeQuery(); rs.setFetchSize(1); while (rs.next()) { @@ -318,7 +320,7 @@ public class ResultSetLiveTest { pstmt.close(); } - assertEquals(3, listOfEmployees.size()); + assertEquals(4, listOfEmployees.size()); } @AfterClass From 435f1982985b316d7f2653997ea7d3ec3a8b2175 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Mon, 28 Jan 2019 01:55:39 -0500 Subject: [PATCH 07/10] applied formatter --- .../main/java/com/baeldung/jdbc/Employee.java | 103 +++++++++--------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java index 88af4902b5..27aef8b82f 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java @@ -3,69 +3,68 @@ package com.baeldung.jdbc; import java.util.Objects; public class Employee { - private int id; - private String name; - private String position; - private double salary; + private int id; + private String name; + private String position; + private double salary; - public Employee() { - } + public Employee() { + } - public Employee(int id, String name, double salary, String position) { - this.id = id; - this.name = name; - this.salary = salary; - this.position = position; - } + public Employee(int id, String name, double salary, String position) { + this.id = id; + this.name = name; + this.salary = salary; + this.position = position; + } - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public double getSalary() { - return salary; - } + public double getSalary() { + return salary; + } - public void setSalary(double salary) { - this.salary = salary; - } + public void setSalary(double salary) { + this.salary = salary; + } - public String getPosition() { - return position; - } + public String getPosition() { + return position; + } - public void setPosition(String position) { - this.position = position; - } + public void setPosition(String position) { + this.position = position; + } - @Override - public int hashCode() { - return Objects.hash(id, name, position, salary); - } + @Override + public int hashCode() { + return Objects.hash(id, name, position, salary); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Employee other = (Employee) obj; - return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) - && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Employee other = (Employee) obj; + return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary); + } } From b4041f577d9a42f7656f664ac42b010e76f470a8 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Mon, 11 Feb 2019 08:28:20 -0500 Subject: [PATCH 08/10] Made holdability example much clear. --- .../com/baeldung/jdbc/ResultSetLiveTest.java | 65 +++++++++++++------ 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 2762aeda5e..4e10f8bd43 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -175,54 +175,60 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { - int numOfRows = 0; + Employee employee = null; dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); while (rs.next()) { - Employee employee = populateResultSet(rs); + if (rs.getString("name") + .equalsIgnoreCase("john")) { + rs.updateString("position", "Senior Engineer"); + rs.updateRow(); + dbConnection.commit(); + employee = populateResultSet(rs); + } } rs.last(); - numOfRows = rs.getRow(); } - assertEquals("Inserted using close cursor after commit", 3, numOfRows); + assertEquals("Update using closed cursor", "Senior Engineer", employee.getPosition()); } @Test public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { - int numOfRows = 0; + Employee employee = null; dbConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); while (rs.next()) { - Employee employee = populateResultSet(rs); + if (rs.getString("name") + .equalsIgnoreCase("john")) { + rs.updateString("name", "John Doe"); + rs.updateRow(); + dbConnection.commit(); + employee = populateResultSet(rs); + } } rs.last(); - numOfRows = rs.getRow(); } - assertEquals("Inserted using hold cursor after commit", 4, numOfRows); + assertEquals("Update using open cursor", "John Doe", employee.getName()); } @Test public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { int numOfRows = 0; try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(3); + rs.absolute(2); rs.deleteRow(); } try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } - assertEquals("Deleted row", 3, numOfRows); + assertEquals("Deleted row", 1, numOfRows); } @Test @@ -231,12 +237,33 @@ public class ResultSetLiveTest { try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { - Assert.assertEquals(1000.0, rs.getDouble("salary")); + Assert.assertEquals(1100.0, rs.getDouble("salary")); - rs.updateDouble("salary", 1100.0); + rs.updateDouble("salary", 1200.0); rs.updateRow(); - Assert.assertEquals(1100.0, rs.getDouble("salary")); + Assert.assertEquals(1200.0, rs.getDouble("salary")); + + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + } + + @Test + public void givenDbConnectionC_whenUpdateByIndex_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + + Assert.assertEquals(1000.0, rs.getDouble(4)); + + rs.updateDouble(4, 1100.0); + rs.updateRow(); + Assert.assertEquals(1100.0, rs.getDouble(4)); String name = rs.getString("name"); Integer empId = rs.getInt("emp_id"); @@ -320,7 +347,7 @@ public class ResultSetLiveTest { pstmt.close(); } - assertEquals(4, listOfEmployees.size()); + assertEquals(2, listOfEmployees.size()); } @AfterClass @@ -329,4 +356,4 @@ public class ResultSetLiveTest { deleteStmt.execute(); dbConnection.close(); } -} +} \ No newline at end of file From 062b959d5a4d127a168d56045d589f0e45d8d5da Mon Sep 17 00:00:00 2001 From: vsurapaneni Date: Tue, 19 Feb 2019 15:33:40 -0500 Subject: [PATCH 09/10] BAEL-2575 --- spring-boot-datasource-issue/pom.xml | 21 +++++++++ .../pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 15 +++++++ .../pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.properties | 2 + .../pom.xml | 45 +++++++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.yml | 4 ++ .../spring-boot-datasource-program/pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../datasourcedemo/DatasourceConfig.java | 18 ++++++++ .../spring-boot-datasource-properties/pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.properties | 4 ++ .../spring-boot-datasource-yml/pom.xml | 45 +++++++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.yml | 6 +++ 18 files changed, 369 insertions(+) create mode 100644 spring-boot-datasource-issue/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml diff --git a/spring-boot-datasource-issue/pom.xml b/spring-boot-datasource-issue/pom.xml new file mode 100644 index 0000000000..2316d86e70 --- /dev/null +++ b/spring-boot-datasource-issue/pom.xml @@ -0,0 +1,21 @@ + + 4.0.0 + spring-boot-datasource-issue + pom + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + spring-boot-datasource-properties + spring-boot-datasource-exclude-program + spring-boot-datasource-exclude-properties + spring-boot-datasource-exclude-yml + spring-boot-datasource-program + spring-boot-datasource-yml + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml new file mode 100644 index 0000000000..8025cc8959 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-exclude-program + spring-boot-datasource-exclude-program + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..b6c81471c4 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} + diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml new file mode 100644 index 0000000000..78d253c4f7 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-exclude-properties + spring-boot-datasource-exclude-properties + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties new file mode 100644 index 0000000000..ae2b359cd0 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration + diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml new file mode 100644 index 0000000000..1d60ea3dbf --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-exclude-yml + spring-boot-datasource-exclude-yml + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + org.yaml + snakeyaml + + + + + Sonatype-public + SnakeYAML repository + http://oss.sonatype.org/content/groups/public/ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml new file mode 100644 index 0000000000..c574bf01a7 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml @@ -0,0 +1,4 @@ +spring: + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml new file mode 100644 index 0000000000..279fcc063b --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-program + spring-boot-datasource-program + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java new file mode 100644 index 0000000000..0eca032d42 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java @@ -0,0 +1,18 @@ +package com.baeldung.datasourcedemo; + + +import javax.sql.DataSource; + +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DatasourceConfig { + @Bean + public DataSource datasource() { + return DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver"). + url("jdbc:mysql://localhost:3306/lonar").username("root").password("Chinna@1988").build(); + } + +} \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml new file mode 100644 index 0000000000..8a7ca75bdd --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-properties + spring-boot-datasource-properties + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties new file mode 100644 index 0000000000..90605e9258 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/lonar +spring.datasource.username=root +spring.datasource.password=Chinna@1988 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml new file mode 100644 index 0000000000..6f474f76db --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-yml + spring-boot-datasource-yml + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + org.yaml + snakeyaml + + + + + Sonatype-public + SnakeYAML repository + http://oss.sonatype.org/content/groups/public/ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml new file mode 100644 index 0000000000..98d7c843e8 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml @@ -0,0 +1,6 @@ +spring: + datasource: + driverClassName: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/lonar + username: root + password: Chinna@1988 From c5d9aceb86b450b2a022c39acc73ddc128b5fb11 Mon Sep 17 00:00:00 2001 From: vsurapaneni Date: Tue, 19 Feb 2019 16:09:52 -0500 Subject: [PATCH 10/10] fixed the mix up with another pr. --- spring-boot-datasource-issue/pom.xml | 21 --------- .../pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 15 ------- .../pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.properties | 2 - .../pom.xml | 45 ------------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.yml | 4 -- .../spring-boot-datasource-program/pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../datasourcedemo/DatasourceConfig.java | 18 -------- .../spring-boot-datasource-properties/pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.properties | 4 -- .../spring-boot-datasource-yml/pom.xml | 45 ------------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.yml | 6 --- 18 files changed, 369 deletions(-) delete mode 100644 spring-boot-datasource-issue/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml diff --git a/spring-boot-datasource-issue/pom.xml b/spring-boot-datasource-issue/pom.xml deleted file mode 100644 index 2316d86e70..0000000000 --- a/spring-boot-datasource-issue/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - 4.0.0 - spring-boot-datasource-issue - pom - - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - spring-boot-datasource-properties - spring-boot-datasource-exclude-program - spring-boot-datasource-exclude-properties - spring-boot-datasource-exclude-yml - spring-boot-datasource-program - spring-boot-datasource-yml - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml deleted file mode 100644 index 8025cc8959..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-exclude-program - spring-boot-datasource-exclude-program - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index b6c81471c4..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; - -@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} - diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml deleted file mode 100644 index 78d253c4f7..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-exclude-properties - spring-boot-datasource-exclude-properties - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties deleted file mode 100644 index ae2b359cd0..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration - diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml deleted file mode 100644 index 1d60ea3dbf..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-exclude-yml - spring-boot-datasource-exclude-yml - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - org.yaml - snakeyaml - - - - - Sonatype-public - SnakeYAML repository - http://oss.sonatype.org/content/groups/public/ - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml deleted file mode 100644 index c574bf01a7..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml +++ /dev/null @@ -1,4 +0,0 @@ -spring: - autoconfigure: - exclude: - - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml deleted file mode 100644 index 279fcc063b..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-program - spring-boot-datasource-program - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java deleted file mode 100644 index 0eca032d42..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.datasourcedemo; - - -import javax.sql.DataSource; - -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class DatasourceConfig { - @Bean - public DataSource datasource() { - return DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver"). - url("jdbc:mysql://localhost:3306/lonar").username("root").password("Chinna@1988").build(); - } - -} \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml deleted file mode 100644 index 8a7ca75bdd..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-properties - spring-boot-datasource-properties - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties deleted file mode 100644 index 90605e9258..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/lonar -spring.datasource.username=root -spring.datasource.password=Chinna@1988 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml deleted file mode 100644 index 6f474f76db..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-yml - spring-boot-datasource-yml - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - org.yaml - snakeyaml - - - - - Sonatype-public - SnakeYAML repository - http://oss.sonatype.org/content/groups/public/ - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml deleted file mode 100644 index 98d7c843e8..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml +++ /dev/null @@ -1,6 +0,0 @@ -spring: - datasource: - driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/lonar - username: root - password: Chinna@1988