当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatement.getResultSet方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.getResultSet方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.getResultSet方法的具体用法?Java PreparedStatement.getResultSet怎么用?Java PreparedStatement.getResultSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.getResultSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDadosCliente

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static ResultSet getDadosCliente(String valor)
{
    ResultSet rs= null;
    try
    {
        System.err.println(valor +" Cliente Selecionado");
        Conexao conexao = new Conexao();
        String sql ="SELECT *from VER_CLIENTE WHERE UPPER(ID) = UPPER( '"+valor+ "')";
        if(conexao.getCon()!=null)
        {
            PreparedStatement ps = conexao.getCon().prepareStatement(sql);
            ps.execute();
            rs = ps.getResultSet();
            rs.next();
        }
    } 
    catch (SQLException ex) 
    {
        Logger.getLogger(ClienteDao.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rs;
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:23,代码来源:ClienteDao.java

示例2: testPreparedStatementExecute

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Test
  public void testPreparedStatementExecute() throws Exception {
    long expectedCount = getTimerCount(executeStatementName) + 1;

    Connection connection = datasource.getConnection();
    PreparedStatement preparedStatement = connection.prepareStatement(SELECT_QUERY);

    int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
    String key = presetElementKeys.get(rnd);
    Integer value = presetElements.get(key);

    preparedStatement.setString(1, key);

//    ResultSet resultSet = preparedStatement.executeQuery();
    preparedStatement.execute();
    ResultSet resultSet = preparedStatement.getResultSet();
    resultSet.next();
    assertEquals(value.intValue(), resultSet.getInt(2));
    connection.close();

    assertEquals(expectedCount,
        getTimerCount(executeStatementName));
  }
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:24,代码来源:JDBCInstrumentationTest.java

示例3: getDadosCliente

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public ResultSet getDadosCliente(String valor)
{
    ResultSet rs= null;
    try
    {
        Conexao conexao = new Conexao();
        String sql ="SELECT *from VER_CLIENTE WHERE UPPER(ID) = UPPER( '"+valor+ "')";
        PreparedStatement ps = conexao.getCon().prepareStatement(sql);
        ps.execute();
        rs = ps.getResultSet();
        rs.next();
    } 
    catch (SQLException ex) 
    {
        Logger.getLogger(ClienteDao.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rs; 
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:19,代码来源:ConsultaCliente.java

示例4: calculateSumDB

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private long calculateSumDB(String table, int columns) throws Exception {
  long result = 0;
  PreparedStatement ps = prepareStatement("SELECT * FROM " + table);

  ps.execute();
  ResultSet rs = ps.getResultSet();

  while (rs.next()) {
    for (int c = 1; c <= columns; c++) {
      String v = rs.getString(c);
      for (int i = 0; v != null && i < v.length(); i++)
        result += v.charAt(i);
    }
  }

  return result;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:18,代码来源:TPCC.java

示例5: checkPingQuery

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void checkPingQuery(Connection c) throws SQLException {
    // Yes, I know we're sending 2, and looking for 1 that's part of the test, since we don't _really_ send the query to the server!
    String aPingQuery = "/* ping */ SELECT 2";
    Statement pingStmt = c.createStatement();
    PreparedStatement pingPStmt = null;

    this.rs = pingStmt.executeQuery(aPingQuery);
    assertTrue(this.rs.next());
    assertEquals(this.rs.getInt(1), 1);

    assertTrue(pingStmt.execute(aPingQuery));
    this.rs = pingStmt.getResultSet();
    assertTrue(this.rs.next());
    assertEquals(this.rs.getInt(1), 1);

    pingPStmt = c.prepareStatement(aPingQuery);

    assertTrue(pingPStmt.execute());
    this.rs = pingPStmt.getResultSet();
    assertTrue(this.rs.next());
    assertEquals(this.rs.getInt(1), 1);

    this.rs = pingPStmt.executeQuery();
    assertTrue(this.rs.next());
    assertEquals(this.rs.getInt(1), 1);

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:28,代码来源:ConnectionRegressionTest.java

示例6: testBug55340

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#55340 - initializeResultsMetadataFromCache fails on second call to stored proc
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug55340() throws Exception {
    Connection testConnCacheRSMD = getConnectionWithProps("cacheResultSetMetadata=true");
    ResultSetMetaData rsmd;

    createTable("testBug55340", "(col1 INT, col2 CHAR(10))");
    createProcedure("testBug55340", "() BEGIN SELECT * FROM testBug55340; END");

    assertEquals(this.stmt.executeUpdate("INSERT INTO testBug55340 (col1, col2) VALUES (1, 'one'), (2, 'two'), (3, 'three')"), 3);

    for (Connection testConn : new Connection[] { this.conn, testConnCacheRSMD }) {
        String testDesc = testConn == testConnCacheRSMD ? "Conn. with 'cacheResultSetMetadata=true'" : "Default connection";

        // bug occurs in 2nd call only
        for (int i = 1; i <= 2; i++) {
            for (PreparedStatement testStmt : new PreparedStatement[] { testConn.prepareStatement("SELECT * FROM testBug55340"),
                    testConn.prepareCall("CALL testBug55340()") }) {

                assertTrue(testStmt.execute());
                this.rs = testStmt.getResultSet();
                assertResultSetLength(this.rs, 3);

                rsmd = this.rs.getMetaData();
                assertEquals("(" + i + ") " + testDesc + " - " + testStmt.getClass().getSimpleName() + ":RSMetaData - wrong column count.", 2,
                        rsmd.getColumnCount());
                assertEquals("(" + i + ") " + testDesc + " - " + testStmt.getClass().getSimpleName() + ":RSMetaData - wrong column(1) type.",
                        Integer.class.getName(), rsmd.getColumnClassName(1));
                assertEquals("(" + i + ") " + testDesc + " - " + testStmt.getClass().getSimpleName() + ":RSMetaData - wrong column(2) type.",
                        String.class.getName(), rsmd.getColumnClassName(2));

                testStmt.close();
            }
        }
    }

    testConnCacheRSMD.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:43,代码来源:StatementRegressionTest.java

示例7: testPreparedStatementExecuteError

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Test
  public void testPreparedStatementExecuteError() throws Exception {
    long expectedCount = getTimerCount(executeStatementName);

    Connection connection = datasource.getConnection();
    PreparedStatement preparedStatement = connection.prepareStatement(SELECT_QUERY);

    boolean gotSqlException = false;
    try {
      preparedStatement.execute();
    } catch (SQLException e) {
      gotSqlException = true;
    }
    assertTrue(gotSqlException);
    assertEquals(expectedCount,
        getTimerCount(executeStatementName));

    expectedCount++;
    int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
    String key = presetElementKeys.get(rnd);
    Integer value = presetElements.get(key);

    preparedStatement.setString(1, key);

//    ResultSet resultSet = preparedStatement.executeQuery();
    preparedStatement.execute();
    ResultSet resultSet = preparedStatement.getResultSet();
    resultSet.next();
    assertEquals(value.intValue(), resultSet.getInt(2));
    connection.close();

    assertEquals(expectedCount,
        getTimerCount(executeStatementName));
  }
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:35,代码来源:JDBCInstrumentationTest.java

示例8: reportQuantity

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void reportQuantity(String table) throws Exception {
  PreparedStatement ps;
  ResultSet rs;

  ps = prepareStatement("SELECT COUNT(*) FROM " + table);
  ps.execute();
  rs = ps.getResultSet();
  rs.first();
  System.err.println(table + " #" + rs.getLong(1));
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:11,代码来源:TPCC.java

示例9: testBug71396PrepStatementCheck

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Executes one query using a PreparedStatement and tests if the results count is the expected.
 */
private void testBug71396PrepStatementCheck(PreparedStatement testPStmt, String query, int expRowCount) throws SQLException {
    ResultSet testRS;

    testRS = testPStmt.executeQuery();
    assertTrue(testRS.last());
    assertEquals(String.format("Wrong number of rows for query '%s'", query), expRowCount, testRS.getRow());
    testRS.close();

    testPStmt.execute();
    testRS = testPStmt.getResultSet();
    assertTrue(testRS.last());
    assertEquals(String.format("Wrong number of rows for query '%s'", query), expRowCount, testRS.getRow());
    testRS.close();
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:18,代码来源:StatementRegressionTest.java

示例10: testPrepareOfMultiRs

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void testPrepareOfMultiRs() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return;
    }

    createProcedure("p", "() begin select 1; select 2; end;");

    PreparedStatement ps = null;

    try {
        ps = this.conn.prepareStatement("call p()");

        ps.execute();
        this.rs = ps.getResultSet();
        assertTrue(this.rs.next());
        assertEquals(1, this.rs.getInt(1));
        assertTrue(ps.getMoreResults());
        this.rs = ps.getResultSet();
        assertTrue(this.rs.next());
        assertEquals(2, this.rs.getInt(1));
        assertTrue(!ps.getMoreResults());
    } finally {
        if (this.rs != null) {
            this.rs.close();
            this.rs = null;
        }

        if (ps != null) {
            ps.close();
        }
    }

}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:34,代码来源:CallableStatementRegressionTest.java

示例11: DevolverValorCampo

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static String DevolverValorCampo(String campoRetorno,String campoSql, String view, String valor)
{
    String sql;
    String resultado = null;
    PreparedStatement ps;
    ResultSet rs;
    sql = "SELECT "+campoRetorno+" FROM "+view+" WHERE "+campoSql+"=?";
       Conexao conexao = new Conexao();
    try
    {
        if(conexao.getCon()!=null)
        {
            ps = conexao.getCon().prepareStatement(sql);
            ps.setString(1, valor);
            ps.execute();
            rs = ps.getResultSet();
            if( rs!= null)
            {
                while(rs.next())
                {
                    resultado = rs.getString(campoRetorno);
                }
                rs.close();
                conexao.destruir();
            }
        }
        System.out.println("resultado "+resultado);
    }
    catch (SQLException ex)
    {
        Logger.getLogger(ClienteDao.class.getName()).log(Level.SEVERE, null, ex);
    }
    return resultado;
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:35,代码来源:Validacao.java

示例12: execute

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void execute (Database database) throws CustomChangeException
{
   String rootName = CollectionDao.COLLECTION_ROOT_NAME;
   String rootId = "SELECT UUID FROM COLLECTIONS WHERE NAME='%s'";
   String auth = "DELETE FROM COLLECTION_USER_AUTH WHERE COLLECTIONS_UUID='%s'";
   String delete = "DELETE FROM COLLECTIONS WHERE NAME='%s'";
   try
   {
      String cid = null;
      String sql;
      PreparedStatement statement;
      JdbcConnection connection = (JdbcConnection) database.getConnection ();

      // get root collection id
      sql = String.format (rootId, rootName);
      statement = connection.prepareStatement (sql);
      statement.execute ();
      ResultSet resultSet = statement.getResultSet ();
      if (resultSet.next ())
      {
         cid = resultSet.getString (1);
      }
      statement.close ();

      if (cid != null)
      {
         // remove default authorization on root collection
         sql = String.format (auth, cid);
         statement = connection.prepareStatement (sql);
         statement.execute ();
         statement.close ();

         // delete root collection
         sql = String.format (delete, rootName);
         statement = connection.prepareStatement (sql);
         statement.execute ();
         statement.close ();
      }
   }
   catch (DatabaseException | SQLException e)
   {
      throw new CustomChangeException (e);
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:46,代码来源:FlatCollection.java

示例13: getTablesFromCache

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static ResultSet getTablesFromCache(final Connection connCache, String catalog, String schemaPattern,
		String tableNamePattern, String[] types) throws SQLException {
	int indexCol = 1;
	String sql = "SELECT * FROM GMETA_TABLES";
	boolean isFirstCondition = true;
	if (catalog != null && catalog.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_CAT LIKE ?";
	}
	if (schemaPattern != null && schemaPattern.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_SCHEM LIKE ?";
	}
	if (tableNamePattern != null && tableNamePattern.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_NAME LIKE ?";
	}
	sql += " ORDER BY TABLE_TYPE, TABLE_CAT, TABLE_SCHEM, TABLE_NAME";

	final PreparedStatement pstmt = connCache.prepareStatement(sql);

	if (catalog != null && catalog.trim().length() != 0) {
		pstmt.setString(indexCol++, catalog);
	}
	if (schemaPattern != null && schemaPattern.trim().length() != 0) {
		pstmt.setString(indexCol++, schemaPattern);
	}
	if (tableNamePattern != null && tableNamePattern.trim().length() != 0) {
		pstmt.setString(indexCol++, tableNamePattern);
	}

	pstmt.executeQuery();
	return pstmt.getResultSet();
}
 
开发者ID:igapyon,项目名称:blanco-sfdc-jdbc-driver,代码行数:50,代码来源:BlancoGenericJdbcCacheUtilDatabaseMetaData.java

示例14: getColumnsFromCache

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static ResultSet getColumnsFromCache(final Connection connCache, String cacheTableName, String catalog,
		String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
	if (cacheTableName == null) {
		cacheTableName = "GMETA_COLUMNS";
	}

	String sql = "SELECT * FROM " + cacheTableName; //
	boolean isFirstCondition = true;
	if (catalog != null && catalog.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_CAT = ?";
	}
	if (schemaPattern != null && schemaPattern.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_SCHEM LIKE ?";
	}
	if (tableNamePattern != null && tableNamePattern.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_NAME LIKE ?";
	}
	if (columnNamePattern != null && columnNamePattern.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " COLUMN_NAME LIKE ?";
	}

	sql += " ORDER BY TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION";

	final PreparedStatement pstmt = connCache.prepareStatement(sql);

	int indexCol = 1;
	if (catalog != null && catalog.trim().length() != 0) {
		pstmt.setString(indexCol++, catalog);
	}
	if (schemaPattern != null && schemaPattern.trim().length() != 0) {
		pstmt.setString(indexCol++, schemaPattern);
	}
	if (tableNamePattern != null && tableNamePattern.trim().length() != 0) {
		pstmt.setString(indexCol++, tableNamePattern);
	}
	if (columnNamePattern != null && columnNamePattern.trim().length() != 0) {
		pstmt.setString(indexCol++, columnNamePattern);
	}

	pstmt.executeQuery();
	return pstmt.getResultSet();
}
 
开发者ID:igapyon,项目名称:blanco-sfdc-jdbc-driver,代码行数:67,代码来源:BlancoGenericJdbcCacheUtilDatabaseMetaData.java

示例15: isCacheDatabaseMetaDataColumnsCached

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static boolean isCacheDatabaseMetaDataColumnsCached(final Connection connCache, String catalog,
		String schemaPattern, String tableName) throws SQLException {
	boolean isCached = false;

	String sql = "SELECT COUNT(*) FROM GMETA_COLUMNS";

	boolean isFirstCondition = true;
	if (catalog != null && catalog.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_CAT = ?";
	}
	if (schemaPattern != null && schemaPattern.trim().length() != 0) {
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_SCHEM LIKE ?";
	}
	{
		if (isFirstCondition) {
			isFirstCondition = false;
			sql += " WHERE";
		} else {
			sql += " AND";
		}
		sql += " TABLE_NAME = ?";
	}

	final PreparedStatement pstmt = connCache.prepareStatement(sql);
	try {
		int indexCol = 1;
		if (catalog != null && catalog.trim().length() != 0) {
			pstmt.setString(indexCol++, catalog);
		}
		if (schemaPattern != null && schemaPattern.trim().length() != 0) {
			pstmt.setString(indexCol++, schemaPattern);
		}
		pstmt.setString(indexCol++, tableName);

		pstmt.executeQuery();
		ResultSet rs = pstmt.getResultSet();
		rs.next();
		if (rs.getInt(1) > 0) {
			isCached = true;
		}
		rs.close();
		return isCached;
	} finally {
		pstmt.close();
	}
}
 
开发者ID:igapyon,项目名称:blanco-sfdc-jdbc-driver,代码行数:59,代码来源:BlancoGenericJdbcCacheUtilDatabaseMetaData.java


注:本文中的java.sql.PreparedStatement.getResultSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。