コード例 #1
0
 @Override
 public int getConcurrency() throws SQLException {
   try {
     return _res.getConcurrency();
   } catch (SQLException e) {
     handleException(e);
     return 0;
   }
 }
コード例 #2
0
  // Bugzilla Bug 24328: PooledConnectionImpl ignores resultsetType
  // and Concurrency if statement pooling is not enabled
  // http://issues.apache.org/bugzilla/show_bug.cgi?id=24328
  public void testPrepareStatementOptions() throws Exception {
    Connection conn = newConnection();
    assertNotNull(conn);
    PreparedStatement stmt =
        conn.prepareStatement(
            "select * from dual", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    assertNotNull(stmt);
    ResultSet rset = stmt.executeQuery();
    assertNotNull(rset);
    assertTrue(rset.next());

    assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, rset.getType());
    assertEquals(ResultSet.CONCUR_UPDATABLE, rset.getConcurrency());

    rset.close();
    stmt.close();
    conn.close();
  }
コード例 #3
0
  private void testInt() throws SQLException {
    trace("Test INT");
    ResultSet rs;
    Object o;

    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE INT)");
    stat.execute("INSERT INTO TEST VALUES(1,-1)");
    stat.execute("INSERT INTO TEST VALUES(2,0)");
    stat.execute("INSERT INTO TEST VALUES(3,1)");
    stat.execute("INSERT INTO TEST VALUES(4," + Integer.MAX_VALUE + ")");
    stat.execute("INSERT INTO TEST VALUES(5," + Integer.MIN_VALUE + ")");
    stat.execute("INSERT INTO TEST VALUES(6,NULL)");
    // this should not be read - maxrows=6
    stat.execute("INSERT INTO TEST VALUES(7,NULL)");

    // MySQL compatibility (is this required?)
    // rs=stat.executeQuery("SELECT * FROM TEST T ORDER BY ID");
    // check(rs.findColumn("T.ID"), 1);
    // check(rs.findColumn("T.NAME"), 2);

    rs = stat.executeQuery("SELECT *, NULL AS N FROM TEST ORDER BY ID");

    // MySQL compatibility
    assertEquals(1, rs.findColumn("TEST.ID"));
    assertEquals(2, rs.findColumn("TEST.VALUE"));

    ResultSetMetaData meta = rs.getMetaData();
    assertEquals(3, meta.getColumnCount());
    assertEquals("resultSet".toUpperCase(), meta.getCatalogName(1));
    assertTrue("PUBLIC".equals(meta.getSchemaName(2)));
    assertTrue("TEST".equals(meta.getTableName(1)));
    assertTrue("ID".equals(meta.getColumnName(1)));
    assertTrue("VALUE".equals(meta.getColumnName(2)));
    assertTrue(!meta.isAutoIncrement(1));
    assertTrue(meta.isCaseSensitive(1));
    assertTrue(meta.isSearchable(1));
    assertFalse(meta.isCurrency(1));
    assertTrue(meta.getColumnDisplaySize(1) > 0);
    assertTrue(meta.isSigned(1));
    assertTrue(meta.isSearchable(2));
    assertEquals(ResultSetMetaData.columnNoNulls, meta.isNullable(1));
    assertFalse(meta.isReadOnly(1));
    assertTrue(meta.isWritable(1));
    assertFalse(meta.isDefinitelyWritable(1));
    assertTrue(meta.getColumnDisplaySize(1) > 0);
    assertTrue(meta.getColumnDisplaySize(2) > 0);
    assertEquals(null, meta.getColumnClassName(3));

    assertTrue(rs.getRow() == 0);
    assertResultSetMeta(
        rs,
        3,
        new String[] {"ID", "VALUE", "N"},
        new int[] {Types.INTEGER, Types.INTEGER, Types.NULL},
        new int[] {10, 10, 1},
        new int[] {0, 0, 0});
    rs.next();
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
    trace("default fetch size=" + rs.getFetchSize());
    // 0 should be an allowed value (but it's not defined what is actually
    // means)
    rs.setFetchSize(0);
    assertThrows(ErrorCode.INVALID_VALUE_2, rs).setFetchSize(-1);
    // fetch size 100 is bigger than maxrows - not allowed
    assertThrows(ErrorCode.INVALID_VALUE_2, rs).setFetchSize(100);
    rs.setFetchSize(6);

    assertTrue(rs.getRow() == 1);
    assertEquals(2, rs.findColumn("VALUE"));
    assertEquals(2, rs.findColumn("value"));
    assertEquals(2, rs.findColumn("Value"));
    assertEquals(2, rs.findColumn("Value"));
    assertEquals(1, rs.findColumn("ID"));
    assertEquals(1, rs.findColumn("id"));
    assertEquals(1, rs.findColumn("Id"));
    assertEquals(1, rs.findColumn("iD"));
    assertTrue(rs.getInt(2) == -1 && !rs.wasNull());
    assertTrue(rs.getInt("VALUE") == -1 && !rs.wasNull());
    assertTrue(rs.getInt("value") == -1 && !rs.wasNull());
    assertTrue(rs.getInt("Value") == -1 && !rs.wasNull());
    assertTrue(rs.getString("Value").equals("-1") && !rs.wasNull());

    o = rs.getObject("value");
    trace(o.getClass().getName());
    assertTrue(o instanceof Integer);
    assertTrue(((Integer) o).intValue() == -1);
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof Integer);
    assertTrue(((Integer) o).intValue() == -1);
    assertTrue(rs.getBoolean("Value"));
    assertTrue(rs.getByte("Value") == (byte) -1);
    assertTrue(rs.getShort("Value") == (short) -1);
    assertTrue(rs.getLong("Value") == -1);
    assertTrue(rs.getFloat("Value") == -1.0);
    assertTrue(rs.getDouble("Value") == -1.0);

    assertTrue(rs.getString("Value").equals("-1") && !rs.wasNull());
    assertTrue(rs.getInt("ID") == 1 && !rs.wasNull());
    assertTrue(rs.getInt("id") == 1 && !rs.wasNull());
    assertTrue(rs.getInt("Id") == 1 && !rs.wasNull());
    assertTrue(rs.getInt(1) == 1 && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 2);
    assertTrue(rs.getInt(2) == 0 && !rs.wasNull());
    assertTrue(!rs.getBoolean(2));
    assertTrue(rs.getByte(2) == 0);
    assertTrue(rs.getShort(2) == 0);
    assertTrue(rs.getLong(2) == 0);
    assertTrue(rs.getFloat(2) == 0.0);
    assertTrue(rs.getDouble(2) == 0.0);
    assertTrue(rs.getString(2).equals("0") && !rs.wasNull());
    assertTrue(rs.getInt(1) == 2 && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 3);
    assertTrue(rs.getInt("ID") == 3 && !rs.wasNull());
    assertTrue(rs.getInt("VALUE") == 1 && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 4);
    assertTrue(rs.getInt("ID") == 4 && !rs.wasNull());
    assertTrue(rs.getInt("VALUE") == Integer.MAX_VALUE && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 5);
    assertTrue(rs.getInt("id") == 5 && !rs.wasNull());
    assertTrue(rs.getInt("value") == Integer.MIN_VALUE && !rs.wasNull());
    assertTrue(rs.getString(1).equals("5") && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 6);
    assertTrue(rs.getInt("id") == 6 && !rs.wasNull());
    assertTrue(rs.getInt("value") == 0 && rs.wasNull());
    assertTrue(rs.getInt(2) == 0 && rs.wasNull());
    assertTrue(rs.getInt(1) == 6 && !rs.wasNull());
    assertTrue(rs.getString(1).equals("6") && !rs.wasNull());
    assertTrue(rs.getString(2) == null && rs.wasNull());
    o = rs.getObject(2);
    assertTrue(o == null);
    assertTrue(rs.wasNull());
    assertFalse(rs.next());
    assertEquals(0, rs.getRow());
    // there is one more row, but because of setMaxRows we don't get it

    stat.execute("DROP TABLE TEST");
    stat.setMaxRows(0);
  }
コード例 #4
0
  private void testClob() throws SQLException {
    trace("Test CLOB");
    ResultSet rs;
    String string;
    stat = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE CLOB)");
    stat.execute("INSERT INTO TEST VALUES(1,'Test')");
    stat.execute("INSERT INTO TEST VALUES(2,'Hello')");
    stat.execute("INSERT INTO TEST VALUES(3,'World!')");
    stat.execute("INSERT INTO TEST VALUES(4,'Hallo')");
    stat.execute("INSERT INTO TEST VALUES(5,'Welt!')");
    stat.execute("INSERT INTO TEST VALUES(6,NULL)");
    stat.execute("INSERT INTO TEST VALUES(7,NULL)");
    rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
    assertResultSetMeta(
        rs,
        2,
        new String[] {"ID", "VALUE"},
        new int[] {Types.INTEGER, Types.CLOB},
        new int[] {10, Integer.MAX_VALUE},
        new int[] {0, 0});
    rs.next();
    Object obj = rs.getObject(2);
    assertTrue(obj instanceof java.sql.Clob);
    string = rs.getString(2);
    assertTrue(string != null && string.equals("Test"));
    assertTrue(!rs.wasNull());
    rs.next();
    InputStreamReader reader = null;
    try {
      reader = new InputStreamReader(rs.getAsciiStream(2), "ISO-8859-1");
    } catch (Exception e) {
      assertTrue(false);
    }
    string = readString(reader);
    assertTrue(!rs.wasNull());
    trace(string);
    assertTrue(string != null && string.equals("Hello"));
    rs.next();
    try {
      reader = new InputStreamReader(rs.getAsciiStream("value"), "ISO-8859-1");
    } catch (Exception e) {
      assertTrue(false);
    }
    string = readString(reader);
    assertTrue(!rs.wasNull());
    trace(string);
    assertTrue(string != null && string.equals("World!"));
    rs.next();
    string = readString(rs.getCharacterStream(2));
    assertTrue(!rs.wasNull());
    trace(string);
    assertTrue(string != null && string.equals("Hallo"));
    rs.next();
    string = readString(rs.getCharacterStream("value"));
    assertTrue(!rs.wasNull());
    trace(string);
    assertTrue(string != null && string.equals("Welt!"));
    rs.next();
    assertTrue(rs.getCharacterStream(2) == null);
    assertTrue(rs.wasNull());
    rs.next();
    assertTrue(rs.getAsciiStream("Value") == null);
    assertTrue(rs.wasNull());

    assertTrue(rs.getStatement() == stat);
    assertTrue(rs.getWarnings() == null);
    rs.clearWarnings();
    assertTrue(rs.getWarnings() == null);
    assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs.next();
    stat.execute("DROP TABLE TEST");
  }
コード例 #5
0
	public int getConcurrency() throws SQLException {
		return rs.getConcurrency();
	}
コード例 #6
0
  private void testDetectUpdatable() throws SQLException {
    Connection conn = getConnection();
    Statement stat;
    ResultSet rs;
    stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

    stat.execute("create table test(id int primary key, name varchar)");
    rs = stat.executeQuery("select * from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    stat.execute("drop table test");

    stat.execute("create table test(a int, b int, " + "name varchar, primary key(a, b))");
    rs = stat.executeQuery("select * from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select a, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select b, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select b, name, a from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    stat.execute("drop table test");

    stat.execute("create table test(a int, b int, name varchar)");
    stat.execute("create unique index on test(b, a)");
    rs = stat.executeQuery("select * from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select a, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select b, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select b, name, a from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    stat.execute("drop table test");

    stat.execute(
        "create table test(a int, b int, c int unique, " + "name varchar, primary key(a, b))");
    rs = stat.executeQuery("select * from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select a, name, c from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select b, a, name, c from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    stat.execute("drop table test");

    stat.execute(
        "create table test(id int primary key, "
            + "a int, b int, i int, j int, k int, name varchar)");
    stat.execute("create unique index on test(b, a)");
    stat.execute("create unique index on test(i, j)");
    stat.execute("create unique index on test(a, j)");
    rs = stat.executeQuery("select * from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select a, name, b from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select a, name, b from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    rs = stat.executeQuery("select i, b, k, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select a, i, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select b, i, k, name from test");
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    rs = stat.executeQuery("select a, k, j, name from test");
    assertEquals(ResultSet.CONCUR_UPDATABLE, rs.getConcurrency());
    stat.execute("drop table test");

    conn.close();
  }
コード例 #7
0
ファイル: Search.java プロジェクト: MotoEdition/MotoEdition
  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) throws SQLException {

    createConnection();
    System.out.println(conn);

    System.out.println("Lol");
    jList1.setModel(new DefaultListModel());

    String name1 = jTextField1.getText();
    String name2 = jTextField2.getText();
    String phone = jTextField3.getText();
    String brand = jTextField4.getText();
    String model = jTextField5.getText();

    Statement sta = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);

    final ResultSet res = sta.executeQuery("SELECT * FROM Orders3");
    if (res.getConcurrency() == ResultSet.CONCUR_READ_ONLY) {
      System.out.println("ResultSet non-updatable.");
    } else {
      System.out.println("ResultSet updatable.");
    }

    while (res.next()) {

      String name1_ = res.getString("Name1");
      String name2_ = res.getString("Name2");
      String phone_ = res.getString("Telephone");
      String brand_ = res.getString("Brand");
      String model_ = res.getString("Model");

      int result = name1.compareTo(name1_);
      int result1 = name2.compareTo(name2_);
      int result2 = phone.compareTo(phone_);
      int result3 = brand.compareTo(brand_);
      int result4 = model.compareTo(model_);

      if (result == 0 || result1 == 0 || result2 == 0 || result3 == 0 || result4 == 0) {

        jList1.setModel(
            new javax.swing.AbstractListModel() {
              {
                String[] s = new String[Orders.length + 1];
                for (int i = 0; i < Orders.length; i++) {
                  s[i] = Orders[i];
                }
                s[Orders.length] =
                    ("  "
                        + res.getInt("ID")
                        + ", "
                        + res.getString("Name1")
                        + ", "
                        + res.getString("Name2")
                        + ", "
                        + res.getString("Telephone")
                        + ", "
                        + res.getString("Brand")
                        + ", "
                        + res.getString("Model")
                        + ", "
                        + res.getString("Problem")
                        + ", "
                        + res.getString("Time")
                        + ", "
                        + res.getString("Price")
                        + ", "
                        + res.getString("Status"));
                Orders = s;
              }

              public int getSize() {
                return Orders.length;
              }

              public Object getElementAt(int i) {
                return Orders[i];
              }
            });
      }
    }

    res.close();

    sta.close();
  }