Merge pull request #9833 from alimate/BAEL-4473
BAEL-4473: Applying TRW Blocks
This commit is contained in:
commit
252ff05ab2
@ -1,6 +1,9 @@
|
|||||||
package com.baeldung.jdbc;
|
package com.baeldung.jdbc;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.CallableStatement;
|
import java.sql.CallableStatement;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -16,10 +19,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.After;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class JdbcLiveTest {
|
public class JdbcLiveTest {
|
||||||
|
|
||||||
@ -33,10 +34,11 @@ public class JdbcLiveTest {
|
|||||||
|
|
||||||
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDb?noAccessToProcedureBodies=true", "user1", "pass");
|
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDb?noAccessToProcedureBodies=true", "user1", "pass");
|
||||||
|
|
||||||
Statement stmt = con.createStatement();
|
try (Statement stmt = con.createStatement()) {
|
||||||
|
|
||||||
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)";
|
||||||
stmt.execute(tableSql);
|
stmt.execute(tableSql);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,10 +103,8 @@ public class JdbcLiveTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallProcedure_thenCorrect() {
|
public void whenCallProcedure_thenCorrect() {
|
||||||
|
|
||||||
try {
|
|
||||||
String preparedSql = "{call insertEmployee(?,?,?,?)}";
|
String preparedSql = "{call insertEmployee(?,?,?,?)}";
|
||||||
CallableStatement cstmt = con.prepareCall(preparedSql);
|
try (CallableStatement cstmt = con.prepareCall(preparedSql)) {
|
||||||
cstmt.setString(2, "ana");
|
cstmt.setString(2, "ana");
|
||||||
cstmt.setString(3, "tester");
|
cstmt.setString(3, "tester");
|
||||||
cstmt.setDouble(4, 2000);
|
cstmt.setDouble(4, 2000);
|
||||||
@ -121,10 +121,11 @@ public class JdbcLiveTest {
|
|||||||
public void whenReadMetadata_thenCorrect() throws SQLException {
|
public void whenReadMetadata_thenCorrect() throws SQLException {
|
||||||
|
|
||||||
DatabaseMetaData dbmd = con.getMetaData();
|
DatabaseMetaData dbmd = con.getMetaData();
|
||||||
ResultSet tablesResultSet = dbmd.getTables(null, null, "%", null);
|
try (ResultSet tablesResultSet = dbmd.getTables(null, null, "%", null)) {
|
||||||
while (tablesResultSet.next()) {
|
while (tablesResultSet.next()) {
|
||||||
LOG.info(tablesResultSet.getString("TABLE_NAME"));
|
LOG.info(tablesResultSet.getString("TABLE_NAME"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String selectSql = "SELECT * FROM employees";
|
String selectSql = "SELECT * FROM employees";
|
||||||
Statement stmt = con.createStatement();
|
Statement stmt = con.createStatement();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user