OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OmniSciPrepareTest.java
Go to the documentation of this file.
1 package com.omnisci.jdbc;
2 
3 import static org.junit.Assert.assertEquals;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Ignore;
8 import org.junit.Test;
9 
10 import java.sql.*;
11 import java.util.Properties;
12 
13 public class OmniSciPrepareTest {
14  static Properties PROPERTIES = new Property_loader("prepare_test.properties");
15  static final String url = PROPERTIES.getProperty("default_db_connection_url");
16  static final String user = PROPERTIES.getProperty("default_super_user");
17  static final String password = PROPERTIES.getProperty("default_user_password");
18 
19  private Connection m_conn = null;
20 
21  @Before
22  public void setUp() throws Exception {
23  Properties pt = new Properties();
24  pt.setProperty("user", user);
25  pt.setProperty("password", password);
26  m_conn = DriverManager.getConnection(url, pt);
27  }
28 
29  @After
30  public void tearDown() throws Exception {
31  m_conn.close();
32  }
33 
34  @Test
35  public void prepare_test() throws Exception {
36  Statement statement = m_conn.createStatement();
37  {
38  statement.executeUpdate(PROPERTIES.getProperty("drop_base_t1"));
39  statement.executeUpdate(PROPERTIES.getProperty("create_base_t1"));
40  String prepare_insert_statement =
41  "insert into test_prepare_table1 (cc, bb, aa) values (?,?,?)";
42  PreparedStatement pr1 = m_conn.prepareStatement(prepare_insert_statement);
43  int aa_i = 100;
44  int bb_i = 1000;
45  int cc_i = 10000;
46  pr1.setInt(1, cc_i);
47  pr1.setInt(2, bb_i);
48  pr1.setInt(3, aa_i);
49  pr1.executeUpdate();
50  ResultSet rs = statement.executeQuery("select cc, bb, aa from test_prepare_table1");
51 
52  while (rs.next()) {
53  int returned_cc = rs.getInt("cc");
54  assertEquals(cc_i, returned_cc);
55  int returned_bb = rs.getInt("bb");
56  assertEquals(bb_i, returned_bb);
57  int returned_aa = rs.getInt("aa");
58  assertEquals(aa_i, returned_aa);
59  }
60  statement.executeUpdate(PROPERTIES.getProperty("drop_base_t1"));
61  }
62  {
63  statement.executeUpdate(PROPERTIES.getProperty("drop_base_t2"));
64  statement.executeUpdate(PROPERTIES.getProperty("create_base_t2"));
65  String prepare_insert_statement2 =
66  "insert into test_prepare_table2 (cc, bb, aa) values (?,?,?)";
67  PreparedStatement pr2 = m_conn.prepareStatement(prepare_insert_statement2);
68  String aa_s = "100";
69  String bb_s = "1000";
70  String cc_s = "10000";
71  pr2.setString(1, cc_s);
72  pr2.setString(2, bb_s);
73  pr2.setString(3, aa_s);
74  pr2.executeUpdate();
75  ResultSet rs2 =
76  statement.executeQuery("select cc, bb, aa from test_prepare_table2");
77 
78  while (rs2.next()) {
79  String returned_cc = rs2.getString("cc");
80  assertEquals(cc_s, returned_cc);
81  String returned_bb = rs2.getString("bb");
82  assertEquals(bb_s, returned_bb);
83  String returned_aa = rs2.getString("aa");
84  assertEquals(aa_s, returned_aa);
85  }
86  statement.executeUpdate(PROPERTIES.getProperty("drop_base_t2"));
87  }
88  }
89 }