Fixed unit tests and equals method for ResultSetLiveTest
This commit is contained in:
		
							parent
							
								
									f5c4e3af74
								
							
						
					
					
						commit
						eb8f0cf66c
					
				| @ -1,5 +1,7 @@ | |||||||
| package com.baeldung.jdbc; | package com.baeldung.jdbc; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Objects; | ||||||
|  | 
 | ||||||
| public class Employee { | public class Employee { | ||||||
| 	private int id; | 	private int id; | ||||||
| 	private String name; | 	private String name; | ||||||
| @ -48,8 +50,22 @@ public class Employee { | |||||||
| 		this.position = position; | 		this.position = position; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	@Override | ||||||
|  | 	public int hashCode() { | ||||||
|  | 		return Objects.hash(id, name, position, salary); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean equals(Object obj) { | 	public boolean equals(Object obj) { | ||||||
|         return this.getId() == ((Employee) obj).getId(); | 		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); | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -38,11 +38,13 @@ public class ResultSetLiveTest { | |||||||
| 	@BeforeClass | 	@BeforeClass | ||||||
| 	public static void setup() throws ClassNotFoundException, SQLException { | 	public static void setup() throws ClassNotFoundException, SQLException { | ||||||
| 		Class.forName("com.mysql.cj.jdbc.Driver"); | 		Class.forName("com.mysql.cj.jdbc.Driver"); | ||||||
|         dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); | 		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)"; | 		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()) { | 		try (Statement stmt = dbConnection.createStatement()) { | ||||||
| 			stmt.execute(tableSql); | 			stmt.execute(tableSql); | ||||||
|             try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { | 			try (PreparedStatement pstmt = dbConnection.prepareStatement( | ||||||
|  | 					"INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { | ||||||
| 				pstmt.executeUpdate(); | 				pstmt.executeUpdate(); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -51,7 +53,8 @@ public class ResultSetLiveTest { | |||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { | 	public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { | ||||||
| 		Employee employee = null; | 		Employee employee = null; | ||||||
|         try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { | 		try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); | ||||||
|  | 				ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			while (rs.next()) { | 			while (rs.next()) { | ||||||
| 				String name = rs.getString("name"); | 				String name = rs.getString("name"); | ||||||
| 				Integer empId = rs.getInt("emp_id"); | 				Integer empId = rs.getInt("emp_id"); | ||||||
| @ -67,7 +70,8 @@ public class ResultSetLiveTest { | |||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { | 	public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { | ||||||
| 		Employee employee = null; | 		Employee employee = null; | ||||||
|         try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { | 		try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); | ||||||
|  | 				ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			while (rs.next()) { | 			while (rs.next()) { | ||||||
| 				Integer empId = rs.getInt(1); | 				Integer empId = rs.getInt(1); | ||||||
| 				String name = rs.getString(2); | 				String name = rs.getString(2); | ||||||
| @ -77,13 +81,14 @@ public class ResultSetLiveTest { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Employee information retreived by column ids.", employee, expectedEmployee1); | 		assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { | 	public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { | ||||||
| 		int rowCount = 0; | 		int rowCount = 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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			rs.moveToInsertRow(); | 			rs.moveToInsertRow(); | ||||||
| 			rs.updateString("name", "Venkat"); | 			rs.updateString("name", "Venkat"); | ||||||
| 			rs.updateString("position", "DBA"); | 			rs.updateString("position", "DBA"); | ||||||
| @ -94,7 +99,7 @@ public class ResultSetLiveTest { | |||||||
| 			rowCount = rs.getRow(); | 			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 { | 	private Employee populateResultSet(ResultSet rs) throws SQLException { | ||||||
| @ -110,40 +115,44 @@ public class ResultSetLiveTest { | |||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { | 	public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { | ||||||
| 		int numOfRows = 0; | 		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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			rs.last(); | 			rs.last(); | ||||||
| 			numOfRows = rs.getRow(); | 			numOfRows = rs.getRow(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Num of rows", numOfRows, rowCount); | 		assertEquals("Num of rows", rowCount, numOfRows); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { | 	public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { | ||||||
| 		Employee secondEmployee = null; | 		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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			rs.absolute(2); | 			rs.absolute(2); | ||||||
| 			secondEmployee = populateResultSet(rs); | 			secondEmployee = populateResultSet(rs); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Absolute navigation", secondEmployee, expectedEmployee2); | 		assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { | 	public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { | ||||||
| 		Employee secondEmployee = null; | 		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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			rs.last(); | 			rs.last(); | ||||||
| 			secondEmployee = populateResultSet(rs); | 			secondEmployee = populateResultSet(rs); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Using Last", secondEmployee, expectedEmployee2); | 		assertEquals("Using Last", expectedEmployee2, secondEmployee); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { | 	public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { | ||||||
| 		Employee firstEmployee = null; | 		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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			while (rs.next()) { | 			while (rs.next()) { | ||||||
| 				Employee employee = populateResultSet(rs); | 				Employee employee = populateResultSet(rs); | ||||||
| 			} | 			} | ||||||
| @ -168,14 +177,15 @@ public class ResultSetLiveTest { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Several Navigation Options", firstEmployee, updatedEmployee1); | 		assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { | 	public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { | ||||||
| 		int numOfRows = 0; | 		int numOfRows = 0; | ||||||
| 		dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); | 		dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); | ||||||
|         try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, 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); | 			dbConnection.setAutoCommit(false); | ||||||
| 			pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); | 			pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); | ||||||
| 			ResultSet rs = pstmt.executeQuery("select * from employees"); | 			ResultSet rs = pstmt.executeQuery("select * from employees"); | ||||||
| @ -187,13 +197,14 @@ public class ResultSetLiveTest { | |||||||
| 			numOfRows = rs.getRow(); | 			numOfRows = rs.getRow(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Inserted using close cursor after commit", numOfRows, 3); | 		assertEquals("Inserted using close cursor after commit", 3, numOfRows); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { | 	public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { | ||||||
| 		int numOfRows = 0; | 		int numOfRows = 0; | ||||||
|         try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, 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); | 			dbConnection.setAutoCommit(false); | ||||||
| 			pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); | 			pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); | ||||||
| 			ResultSet rs = pstmt.executeQuery("select * from employees"); | 			ResultSet rs = pstmt.executeQuery("select * from employees"); | ||||||
| @ -205,26 +216,28 @@ public class ResultSetLiveTest { | |||||||
| 			numOfRows = rs.getRow(); | 			numOfRows = rs.getRow(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Inserted using hold cursor after commit", numOfRows, 4); | 		assertEquals("Inserted using hold cursor after commit", 4, numOfRows); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { | 	public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { | ||||||
| 		int numOfRows = 0; | 		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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			rs.absolute(3); | 			rs.absolute(3); | ||||||
| 			rs.deleteRow(); | 			rs.deleteRow(); | ||||||
| 			rs.last(); | 			rs.last(); | ||||||
| 			numOfRows = rs.getRow(); | 			numOfRows = rs.getRow(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Deleted row", numOfRows, 3); | 		assertEquals("Deleted row", 3, numOfRows); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { | 	public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { | ||||||
| 		Employee employee = null; | 		Employee employee = 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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			while (rs.next()) { | 			while (rs.next()) { | ||||||
| 				rs.updateDouble("salary", 1100.0); | 				rs.updateDouble("salary", 1100.0); | ||||||
| 				rs.updateRow(); | 				rs.updateRow(); | ||||||
| @ -237,7 +250,7 @@ public class ResultSetLiveTest { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("Employee information updated successfully.", employee, updatedEmployee1); | 		assertEquals("Employee information updated successfully.", updatedEmployee1, employee); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| @ -248,21 +261,29 @@ public class ResultSetLiveTest { | |||||||
| 		boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); | 		boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); | ||||||
| 		boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); | 		boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); | ||||||
| 		boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); | 		boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); | ||||||
|         boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); | 		boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, | ||||||
|         boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); | 				ResultSet.CONCUR_READ_ONLY); | ||||||
|         boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); | 		boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, | ||||||
|         boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); | 				ResultSet.CONCUR_UPDATABLE); | ||||||
|         boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); | 		boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd | ||||||
|         boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); | 				.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(); | 		int rsHoldability = dbmd.getResultSetHoldability(); | ||||||
| 
 | 
 | ||||||
|         assertEquals("checking scroll sensitivity and concur updates : ", concurrency4TypeScrollInSensitiveNConcurUpdatable, true); | 		assertEquals("checking scroll sensitivity and concur updates : ", true, | ||||||
|  | 				concurrency4TypeScrollInSensitiveNConcurUpdatable); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { | 	public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { | ||||||
| 		int columnCount = 0; | 		int columnCount = 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.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { | ||||||
| 			ResultSetMetaData metaData = rs.getMetaData(); | 			ResultSetMetaData metaData = rs.getMetaData(); | ||||||
| 			columnCount = metaData.getColumnCount(); | 			columnCount = metaData.getColumnCount(); | ||||||
| 			for (int i = 1; i <= columnCount; i++) { | 			for (int i = 1; i <= columnCount; i++) { | ||||||
| @ -287,7 +308,7 @@ public class ResultSetLiveTest { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals("column count", columnCount, 4); | 		assertEquals("column count", 4, columnCount); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| @ -296,7 +317,8 @@ public class ResultSetLiveTest { | |||||||
| 		ResultSet rs = null; | 		ResultSet rs = null; | ||||||
| 		List<Employee> listOfEmployees = new ArrayList<Employee>(); | 		List<Employee> listOfEmployees = new ArrayList<Employee>(); | ||||||
| 		try { | 		try { | ||||||
|             pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); | 			pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, | ||||||
|  | 					ResultSet.CONCUR_READ_ONLY); | ||||||
| 			pstmt.setFetchSize(2); | 			pstmt.setFetchSize(2); | ||||||
| 			rs = pstmt.executeQuery(); | 			rs = pstmt.executeQuery(); | ||||||
| 			rs.setFetchSize(1); | 			rs.setFetchSize(1); | ||||||
| @ -313,12 +335,13 @@ public class ResultSetLiveTest { | |||||||
| 				pstmt.close(); | 				pstmt.close(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         assertEquals(listOfEmployees.size(), 3); | 		assertEquals(3, listOfEmployees.size()); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@AfterClass | 	@AfterClass | ||||||
| 	public static void closeConnection() throws SQLException { | 	public static void closeConnection() throws SQLException { | ||||||
|         PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); | 		PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", | ||||||
|  | 				ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); | ||||||
| 		deleteStmt.execute(); | 		deleteStmt.execute(); | ||||||
| 		dbConnection.close(); | 		dbConnection.close(); | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user