Examples of PreparedStatement


Examples of com.datastax.driver.core.PreparedStatement

        String cql =
            "SELECT schedule_id, time, type, value " +
            "FROM " + MetricsTable.AGGREGATE + " " +
            "WHERE schedule_id = ? AND bucket = ? " +
            "ORDER BY time, type";
        PreparedStatement statement = session.prepare(cql);
        BoundStatement boundStatement = statement.bind(scheduleId, bucket.toString());

        return new SimplePagedResult<AggregateNumericMetric>(boundStatement, new AggregateNumericMetricMapper(),
            storageSession);
    }
View Full Code Here

Examples of com.google.cloud.sql.jdbc.PreparedStatement

    try {
      Connection conn = null;
      DriverManager.registerDriver(new AppEngineDriver());
      conn = DriverManager.getConnection("jdbc:google:rdbms://pcni.org:openhmis:openciss/compass");
      String stmt = "SELECT program_key, program_name, agency_name, program_type, site_geocode, target_pop_a_name, update_time_stamp, units_total, units_available, units_occupied, contact_name, contact_phone, program_address, program_city, program_zip, program_address_full FROM compass.program_profile_info WHERE program_key=?";
      PreparedStatement pstmt = (PreparedStatement)conn.prepareStatement(stmt);
//      try {
//        System.out.println("value=[" + idStr + "]; bytes=" + Arrays.toString(idStr.getBytes("UTF-8")));
//      } catch (UnsupportedEncodingException e) {
//        e.printStackTrace();
//      }
      pstmt.setString(1, id);
      //pstmt.setString(1, "3459");
      pstmt.toString();
      ResultSet rs = pstmt.executeQuery();
      int i = 0;
      while (rs.next()) {
        JsonNode recordNode = mapper.createObjectNode(); // will be of type ObjectNode
        ((ObjectNode)recordNode).put("ProgramKey", rs.getString("program_key"));
        ((ObjectNode)recordNode).put("ProgramName", rs.getString("program_name"));
View Full Code Here

Examples of com.mysql.jdbc.PreparedStatement

    @Test
    public void preProcessShouldBeginTracingPreparedStatementCall() throws Exception {
        final String sql = randomAlphanumeric(20);
        final String schema = randomAlphanumeric(20);

        final PreparedStatement statement = mock(PreparedStatement.class);
        when(statement.getPreparedSql()).thenReturn(sql);
        final Connection connection = mock(Connection.class);
        when(connection.getSchema()).thenReturn(schema);

        assertNull(subject.preProcess(null, statement, connection));
View Full Code Here

Examples of java.sql.PreparedStatement

      info.precision = meta.getColumnDisplaySize(i);
      String name = meta.getColumnName(i);
      String table = meta.getTableName(i);
      String schema = meta.getSchemaName(i);
      if (schema != null) {
        PreparedStatement ps = null;
        try {
          ps = stmt.getConnection().prepareStatement("select attrelid, attnum, typoid from matpg_relatt where attname = ? and relname = ? and nspname = ?");
          ps.setString(1, name);
          ps.setString(2, table);
          ps.setString(3, schema);
          ResultSet rs = ps.executeQuery();
          if (rs.next()) {
            info.reloid = rs.getInt(1);
            info.attnum = rs.getShort(2);
            int specificType = rs.getInt(3);
            if (!rs.wasNull()) {
              info.type = specificType;
            }
          }
        } finally {
          if (ps != null) {
            ps.close();
          }
        }
      }
      result.add(info);
    }
View Full Code Here

Examples of java.sql.PreparedStatement

  }
 
  public static void testCreateTable() throws Exception{
    Class.forName("org.hsqldb.jdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost","sa","");
    PreparedStatement ps = null;
    ResultSet rs = null;
    try{
      //ps = conn.prepareStatement("create table dlog_bookmark (markid INTEGER,logid INTEGER,siteid INTEGER,userid INTEGER,marktype INTEGER,createTime DATE,markorder INTEGER);");
      //ps.executeUpdate();
     
      ps = conn.prepareStatement("SELECT * FROM dlog_user");
      rs = ps.executeQuery();
      while(rs.next()){
        System.out.println(rs.getString("displayName"));
      }
    }finally{
      if(rs!=null)
        rs.close();
      if(ps!=null)
        ps.close();
      if(conn!=null)
        conn.close();
    }
  }
View Full Code Here

Examples of java.sql.PreparedStatement

        }
        deleteDb("memoryUsage");
        conn = getConnection("memoryUsage");
        Statement stat = conn.createStatement();
        stat.execute("create table test(id int, name varchar(255))");
        PreparedStatement prep = conn.prepareStatement("insert into test values(?, space(200))");
        int len = getSize(10000, 100000);
        for (int i = 0; i < len; i++) {
            if (i % 1000 == 0) {
                // trace("[" + i + "/" + len + "] KB: " + MemoryUtils.getMemoryUsed());
            }
            prep.setInt(1, i);
            prep.executeUpdate();
        }
        int base = Utils.getMemoryUsed();
        stat.execute("create index idx_test_id on test(id)");
        System.gc();
        System.gc();
View Full Code Here

Examples of java.sql.PreparedStatement

        // insert
        time = System.currentTimeMillis();
        stat.execute("DROP TABLE IF EXISTS TEST");
        trace("drop=" + (System.currentTimeMillis() - time));
        stat.execute("CREATE CACHED TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
        PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, 'Hello World')");
        printTimeMemory("start", 0);
        time = System.currentTimeMillis();
        for (int i = 0; i < len; i++) {
            prep.setInt(1, i);
            prep.execute();
            if (i % 50000 == 0) {
                trace("  " + (100 * i / len) + "%");
            }
        }
        printTimeMemory("insert", System.currentTimeMillis() - time);

        // update
        time = System.currentTimeMillis();
        prep = conn.prepareStatement("UPDATE TEST SET NAME='Hallo Welt' || ID WHERE ID = ?");
        for (int i = 0; i < len; i++) {
            prep.setInt(1, i);
            prep.execute();
            if (i % 50000 == 0) {
                trace("  " + (100 * i / len) + "%");
            }
        }
        printTimeMemory("update", System.currentTimeMillis() - time);

        // select
        time = System.currentTimeMillis();
        prep = conn.prepareStatement("SELECT * FROM TEST WHERE ID = ?");
        for (int i = 0; i < len; i++) {
            prep.setInt(1, i);
            ResultSet rs = prep.executeQuery();
            rs.next();
            assertFalse(rs.next());
            if (i % 50000 == 0) {
                trace("  " + (100 * i / len) + "%");
            }
        }
        printTimeMemory("select", System.currentTimeMillis() - time);

        // select randomized
        Random random = new Random(1);
        time = System.currentTimeMillis();
        prep = conn.prepareStatement("SELECT * FROM TEST WHERE ID = ?");
        for (int i = 0; i < len; i++) {
            prep.setInt(1, random.nextInt(len));
            ResultSet rs = prep.executeQuery();
            rs.next();
            assertFalse(rs.next());
            if (i % 50000 == 0) {
                trace("  " + (100 * i / len) + "%");
            }
        }
        printTimeMemory("select randomized", System.currentTimeMillis() - time);

        // delete
        time = System.currentTimeMillis();
        prep = conn.prepareStatement("DELETE FROM TEST WHERE ID = ?");
        for (int i = 0; i < len; i++) {
            prep.setInt(1, random.nextInt(len));
            prep.executeUpdate();
            if (i % 50000 == 0) {
                trace("  " + (100 * i / len) + "%");
            }
        }
        printTimeMemory("delete", System.currentTimeMillis() - time);
View Full Code Here

Examples of java.sql.PreparedStatement

        Task[] tasks = new Task[len];
        for (int i = 0; i < len; i++) {
            tasks[i] = new Task() {
                public void call() throws SQLException {
                    Connection c = DriverManager.getConnection(url, user, password);
                    PreparedStatement prep = c.prepareStatement("insert into employee values(?, ?, 0)");
                    int id = getNextId();
                    prep.setInt(1, id);
                    prep.setString(2, "employee " + id);
                    prep.execute();
                    c.close();
                }
            };
            tasks[i].execute();
        }
View Full Code Here

Examples of java.sql.PreparedStatement

    private void testPrecision() throws SQLException {
        Connection conn = getConnection("functions");
        Statement stat = conn.createStatement();
        stat.execute("create alias no_op for \""+getClass().getName()+".noOp\"");
        PreparedStatement prep = conn.prepareStatement("select * from dual where no_op(1.6)=?");
        prep.setBigDecimal(1, new BigDecimal("1.6"));
        ResultSet rs = prep.executeQuery();
        assertTrue(rs.next());

        stat.execute("create aggregate agg_sum for \""+getClass().getName()+"\"");
        rs = stat.executeQuery("select agg_sum(1), sum(1.6) from dual");
        rs.next();
View Full Code Here

Examples of java.sql.PreparedStatement

        ResultSet rs;
        stat.execute("create alias array_test AS "
                + "$$ Integer[] array_test(Integer[] in_array) "
                + "{ return in_array; } $$;");

        PreparedStatement stmt = conn.prepareStatement("select array_test(?) from dual");
        stmt.setObject(1, new Integer[] { 1, 2 });
        rs = stmt.executeQuery();
        rs.next();
        assertEquals(Integer[].class.getName(), rs.getObject(1).getClass().getName());

        CallableStatement call = conn.prepareCall("{ ? = call array_test(?) }");
        call.setObject(2, new Integer[] { 2, 1 });
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.