Created
November 9, 2019 13:00
-
-
Save masayuki038/d6a9f06a47276608f3b3021c78779f2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JdbcTest { | |
private final static String CONNECTION_URL = "jdbc:calcite:model=target/test-classes/model.json"; | |
@BeforeClass | |
public static void setUpOnce() throws ClassNotFoundException { | |
Class.forName("org.apache.calcite.jdbc.Driver"); | |
} | |
@Test | |
public void filterByEmpId() throws Exception { | |
try (Connection conn = DriverManager.getConnection(CONNECTION_URL)) { | |
try (PreparedStatement pstmt = conn.prepareStatement("select emp_id, name from test where emp_id=?")) { | |
pstmt.setLong(1, 1L); | |
try (ResultSet rs = pstmt.executeQuery()) { | |
while (rs.next()) { | |
assertThat(rs.getLong("emp_id"), is(1L)); | |
assertThat(rs.getString("name"), is("test1")); | |
} | |
} | |
} | |
} | |
} | |
@Test | |
public void filterByName() throws Exception { | |
try (Connection conn = DriverManager.getConnection(CONNECTION_URL)) { | |
try (PreparedStatement pstmt = conn.prepareStatement("select emp_id, name from test where name=?")) { | |
pstmt.setString(1, "test2"); | |
try (ResultSet rs = pstmt.executeQuery()) { | |
while (rs.next()) { | |
assertThat(rs.getLong("emp_id"), is(2L)); | |
assertThat(rs.getString("name"), is("test2")); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment