Package java.sql

Examples of java.sql.ResultSet


    String query = "SELECT " + EXP_RESULT_COL
      + " FROM " + EXP_INDEX_TABLE
       + " WHERE " + EXP_TYPE_COL + "='" + expType
      + "' AND " + EXP_SETUP_COL + "='" + expParams + "'";
    String tableName = null;
    ResultSet rs = select(query);
    if (rs.next()) {
      tableName = rs.getString(1);
      if (rs.next()) {
  throw new Exception("More than one index entry "
      + "for experiment config: " + query);
      }
    }
    close(rs);
View Full Code Here


      DataSource ds = (DataSource)new InitialContext().lookup(datasource);
      Connection conn = ds.getConnection();
      boolean load = false;

      Statement st = conn.createStatement();
      ResultSet rs = null;
      try
      {
         rs = st.executeQuery(existsSql.trim());
         rs.close();
      }
      catch (SQLException e)
      {
         load = true;
      }
View Full Code Here

     * @param sql the SQL statement to execute
     * @param expected the expected result value
     * @throws AssertionError if a different result value was returned
     */
    protected void assertSingleValue(Statement stat, String sql, int expected) throws SQLException {
        ResultSet rs = stat.executeQuery(sql);
        assertTrue(rs.next());
        assertEquals(expected, rs.getInt(1));
        assertFalse(rs.next());
    }
View Full Code Here

     * @param stat the statement
     * @param sql the SQL statement to execute
     * @throws AssertionError if a different result value was returned
     */
    protected void assertResult(String expected, Statement stat, String sql) throws SQLException {
        ResultSet rs = stat.executeQuery(sql);
        if (rs.next()) {
            String actual = rs.getString(1);
            assertEquals(expected, actual);
        } else {
            assertEquals(expected, null);
        }
    }
View Full Code Here

     * @param stat1 the connection to the first database
     * @param stat2 the connection to the second database
     * @throws AssertionError if the databases don't match
     */
    protected void assertEqualDatabases(Statement stat1, Statement stat2) throws SQLException {
        ResultSet rs = stat1.executeQuery("select value from information_schema.settings where name='ANALYZE_AUTO'");
        int analyzeAuto = rs.next() ? rs.getInt(1) : 0;
        if (analyzeAuto > 0) {
            stat1.execute("analyze");
            stat2.execute("analyze");
        }
        ResultSet rs1 = stat1.executeQuery("SCRIPT simple NOPASSWORDS");
        ResultSet rs2 = stat2.executeQuery("SCRIPT simple NOPASSWORDS");
        ArrayList<String> list1 = new ArrayList<String>();
        ArrayList<String> list2 = new ArrayList<String>();
        while (rs1.next()) {
            String s1 = rs1.getString(1);
            if (!rs2.next()) {
                fail("expected: " + s1);
            }
            String s2 = rs2.getString(1);
            if (!s1.equals(s2)) {
                list1.add(s1);
                list2.add(s2);
            }
        }
        for (String s : list1) {
            if (!list2.remove(s)) {
                fail("only found in first: " + s);
            }
        }
        assertEquals(0, list2.size());
        assertFalse(rs2.next());
    }
View Full Code Here

        throw e.getTargetException();
      }
    }
    if (decode && (EXECUTEQUERY.equals(method) || GETRESULTSET.equals(method))){
      try {
        ResultSet rs = (ResultSet) m.invoke(statement, args);
        return (new _ResultSet(rs, decode)).getResultSet();
      } catch (InvocationTargetException e) {
        throw e.getTargetException();
      }
    }
View Full Code Here

    Hashtable htLevels = new Hashtable();
    Statement statement;
    String SQLQuery = "SELECT LJLEVEL, LCODE, nvl(LSYSLOGEQUIV,LLEVEL)  LSYSLOGEQUIV " +
                        "FROM TLOGLEVEL " +
                    "ORDER BY LLEVEL";
    ResultSet rs = null;
    Connection jdbc_conn = null;
         
    if (formatOK == false)
    {
      logger.log(Level.FATAL, "Connection parameters are not OK");   
    }
    else
   
      try{
        // connect to database
        Class.forName("oracle.jdbc.driver.OracleDriver");
        jdbc_conn = DriverManager.getConnection(JDBCurl, DbUser, DbPass);
         
        logger.debug( "JDBC Connection OK: " + jdbc_conn.toString());
         
        // get the PL/SQL and corresponding LOG4J log levels
        statement = jdbc_conn.createStatement();
        rs = statement.executeQuery(SQLQuery);
           
        if (rs != null)
        {
          while(rs.next())
          {
            Level l = new DynamicLevel (rs.getInt("LJLEVEL"),rs.getString("LCODE"),rs.getInt("LSYSLOGEQUIV"));
                Integer levelint = new Integer(rs.getInt("LSYSLOGEQUIV"));
             
                htLevels.put(levelint, l);
          }
        }
         
View Full Code Here

 
  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

        // 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);
View Full Code Here

        stat.execute("insert into testNvl2(id, txt1, txt2, num) values(5, '2', null, 1)");
        stat.execute("insert into testNvl2(id, txt1, txt2, num) values(6, '2', null, null)");
        stat.execute("insert into testNvl2(id, txt1, txt2, num) values(7, 'test2', null, null)");

        String query = "SELECT NVL2(txt1, txt1, txt2), txt1 FROM testNvl2 order by id asc";
        ResultSet rs = stat.executeQuery(query);
        rs.next();
        String actual = rs.getString(1);
        assertEquals("test1", actual);
        rs.next();
        actual = rs.getString(1);
        assertEquals("test4", actual);
        rs.next();
        actual = rs.getString(1);
        assertEquals("test5", actual);
        rs.next();
        actual = rs.getString(1);
        assertEquals(null, actual);
        assertEquals(rs.getMetaData().getColumnType(2), rs.getMetaData().getColumnType(1));
        rs.close();

        rs = stat.executeQuery("SELECT NVL2(num, num, txt1), num FROM testNvl2 where id in(5, 6) order by id asc");
        rs.next();
        assertEquals(rs.getMetaData().getColumnType(2), rs.getMetaData().getColumnType(1));

        assertThrows(ErrorCode.DATA_CONVERSION_ERROR_1, stat).
                executeQuery("SELECT NVL2(num, num, txt1), num FROM testNvl2 where id = 7 order by id asc");

        // nvl2 should return expr2's datatype, if expr2 is character data.
        rs = stat.executeQuery("SELECT NVL2(1, 'test', 123), 'test' FROM dual");
        rs.next();
        actual = rs.getString(1);
        assertEquals("test", actual);
        assertEquals(rs.getMetaData().getColumnType(2), rs.getMetaData().getColumnType(1));

        conn.close();
    }
View Full Code Here

TOP

Related Classes of java.sql.ResultSet

Copyright © 2018 www.massapicom. 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.