Java Code Examples for java.sql.ResultSet.getString()

The following are Jave code examples for showing how to use getString() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: stuManager   File: StudentInfoAddFrame.java   View Source Code Vote up 6 votes
public void classAdd() {
	jComboBox1.removeAllItems();
	jComboBox1.addItem("��ѡ��༶");
	try {
		ResultSet rs = conn.getRs(
				"select * from tb_class where specName='" + String.valueOf(jComboBox5.getSelectedItem()) + "' ");
		while (rs.next()) {
			String zhy = rs.getString("className");
			jComboBox1.addItem(zhy);
		}
		rs.close();

	} catch (Exception e) {
		System.out.println(e);
	}
}
 
Example 2
Project: lams   File: StdJDBCDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Select a trigger' state value.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @return the <code>{@link org.quartz.Trigger}</code> object
 */
public String selectTriggerState(Connection conn, TriggerKey triggerKey) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        String state = null;

        ps = conn.prepareStatement(rtp(SELECT_TRIGGER_STATE));
        ps.setString(1, triggerKey.getName());
        ps.setString(2, triggerKey.getGroup());
        rs = ps.executeQuery();

        if (rs.next()) {
            state = rs.getString(COL_TRIGGER_STATE);
        } else {
            state = STATE_DELETED;
        }

        return state.intern();
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }

}
 
Example 3
Project: sstore-soft   File: TestJDBCDriver.java   View Source Code Vote up 6 votes
@Test
public void testAllProcedures() throws SQLException {
    ResultSet procedures =
            conn.getMetaData().getProcedures("blah", "blah", "%");
    int count = 0;
    List<String> names = Arrays.asList(new String[] {"ArbitraryDurationProc", 
    		"TPCCTestProc", "InsertOrders", "InsertWarehouse", "SelectOrders"});
    while (procedures.next()) {
        String procedure = procedures.getString("PROCEDURE_NAME");
        if (procedure.contains(".")) {
            // auto-generated CRUD
        } else {
            assertTrue(names.contains(procedure));
        }
        count++;
    }
    System.out.println("Procedure count is: " + count);
    assertEquals(5, count);
}
 
Example 4
Project: ChronoBike   File: RecordColTypeManagerChar.java   View Source Code Vote up 6 votes
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
	try
	{			
		String csValue = resultSetSource.getString(m_nColSourceIndex);
		if (!resultSetSource.wasNull())
			insertStatementInsert.setString(m_nColSourceIndex, csValue);
		else
			insertStatementInsert.setNull(m_nColSourceIndex, Types.CHAR);
		return true;
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	return false;		
}
 
Example 5
Project: nihonGO   File: DatabaseHandler.java   View Source Code Vote up 6 votes
public List<String> getAllPalab(){
    List<String> palab = new LinkedList<String>();
    String p;
    
    try{
        ResultSet rs;
        rs = stmt.executeQuery("SELECT clave FROM palabra ORDER BY clave");
        while (rs.next()){
            p = rs.getString("clave");
           palab.add(p);    
        }
    }
    catch(SQLException e){
        
    }
    return palab;
}
 
Example 6
Project: happybot   File: WarningManager.java   View Source Code Vote up 5 votes
public String getWarnTargetId(int warnId) {
    try {
        PreparedStatement statement = connection.prepareStatement(SELECT_WARNING);
        statement.setInt(1, warnId);
        ResultSet set = statement.executeQuery();
        if (set.next()) {
            return set.getString("targetid");
        } else {
            return null;
        }
    } catch (SQLException e) {
        return null;
    }
}
 
Example 7
Project: happybot   File: WarningManager.java   View Source Code Vote up 5 votes
public String getWarnReason(int warnId) {
    try {
        PreparedStatement statement = connection.prepareStatement(SELECT_WARNING);
        statement.setInt(1, warnId);
        ResultSet set = statement.executeQuery();
        if (set.next()) {
            return set.getString("reason");
        } else {
            return null;
        }
    } catch (SQLException e) {
        return null;
    }
}
 
Example 8
Project: BibliotecaPS   File: TestHABasics.java   View Source Code Vote up 5 votes
private String getPort() throws Exception {
    ResultSet rs = this.conn.createStatement().executeQuery("show variables like 'port'");
    assertTrue(rs.next());
    String port1 = rs.getString(2);
    rs.close();
    return port1;
}
 
Example 9
Project: Java-Air-Reservation   File: Airport.java   View Source Code Vote up 5 votes
/**
 * constructor with an ID
 */
public Airport(String aid){
    conn = DBConnect.connect();
    PreparedStatement pst = null;
    try {
        String sql = "SELECT * FROM `airport` WHERE `airportID`=?";
        pst = conn.prepareStatement(sql);
        pst.setString(1, aid);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst() ) {     
            return;
        }
        while(rs.next()){
            this.airportID = rs.getString("airportID");
            this.name = rs.getString("name");
            this.city = rs.getString("city");
            this.apstate = rs.getString("apstate");
            this.country = rs.getString("country");
            this.active = rs.getBoolean("active");
            this.exist = true;
        }
        
    } catch (SQLException e) {
        System.out.println("Error:"+e);
        
    }
}
 
Example 10
Project: cf-mta-deploy-service   File: SplitTargetSpaceColumn.java   View Source Code Vote up 5 votes
@Override
public Map<Long, String> extractData(ResultSet resultSet) throws SQLException {
    Map<Long, String> result = new HashMap<>();
    while (resultSet.next()) {
        long id = resultSet.getLong("ID");
        String targetSpace = resultSet.getString("TARGET_SPACE");
        result.put(id, targetSpace);
        logger.debug(String.format("Retrieve data from row ID: '%s' and TARGET_SPACE: '%s'", id, targetSpace));
    }
    return result;
}
 
Example 11
Project: S3-16-d-rescue   File: DistrictDaoImpl.java   View Source Code Vote up 5 votes
@Override
protected ObjectModel mapRecordToModel(final ResultSet resultSet) throws SQLException {
    final District district = new DistrictImpl(
            resultSet.getString("districtID"),
            resultSet.getString("districtLongName"),
            resultSet.getInt("population"));
    return district;
}
 
Example 12
Project: aliyun-maxcompute-data-collectors   File: ManagerCompatExport.java   View Source Code Vote up 5 votes
public void verifyExport(DATATYPES dt, String[] data) throws SQLException {
  LOG.info("Verifying export: " + getTableName());
  // Check that we got back the correct number of records.
  Connection conn = getManager().getConnection();

  PreparedStatement statement = conn.prepareStatement("SELECT "
      + getColName() + " FROM " + getTableName(dt),
      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
  System.out.println("data samples being compared : " + data.length);

  ResultSet rs = null;
  try {
    rs = statement.executeQuery();
    int cnt = 0;
    try {
      while (rs.next()) {
        String tmp = rs.getString(1);
        String expected = data[cnt++];
        System.out.println("Readback, expected" + tmp + " :"
            + expected);
        if (tmp == null) {
          assertNull("Must be null", expected);
        } else {
          assertEquals("Data must match", expected, tmp);
        }
      }
      System.out.println("expected samples : " + data.length
          + " Actual samples : " + cnt);
      assertEquals("Resultset must contain expected samples",
          data.length, cnt);
    } finally {

      rs.close();
    }
  } finally {
    statement.close();
  }

}
 
Example 13
Project: vertx-generator   File: ConfigUtil.java   View Source Code Vote up 5 votes
/**
 * 获得数据库连接
 * 
 * @return
 * @throws Exception
 */
public static List<DatabaseConfig> getDatabaseConfig() throws Exception {
	Connection conn = null;
	Statement stat = null;
	ResultSet rs = null;
	try {
		conn = getConnection();
		stat = conn.createStatement();
		rs = stat.executeQuery("select * from DBSet");
		List<DatabaseConfig> result = new ArrayList<DatabaseConfig>();
		while (rs.next()) {
			String name = rs.getString("name");
			String value = rs.getString("value");
			DatabaseConfig databaseConfig = JSON.parseObject(value, DatabaseConfig.class);
			databaseConfig.setConnName(name);
			result.add(databaseConfig);
		}

		return result;
	} finally {
		if (rs != null)
			rs.close();
		if (stat != null)
			stat.close();
		if (conn != null)
			conn.close();
	}
}
 
Example 14
Project: blanco-sfdc-jdbc-driver   File: BlancoSfdcJdbcPreparedStatementTest.java   View Source Code Vote up 5 votes
public void test001() throws Exception {
	if (BlancoSfdcJdbcTestConstants.isTestWithSfdc() == false)
		return;

	Class.forName("blanco.sfdc.jdbc.driver.BlancoSfdcJdbcDriver");
	try {
		final Properties prop = new Properties();
		final InputStream inStream = new FileInputStream("soqlro.properties");
		prop.load(new BufferedInputStream(inStream));
		inStream.close();

		final String url = prop.getProperty("url",
				"jdbc:blanco:sfdc:soqlro://login.salesforce.com/services/Soap/u/40.0");
		final String user = prop.getProperty("user", "NoUserSpesified");
		final String pass = prop.getProperty("password", "NoPassSpecified");

		final Connection conn = DriverManager.getConnection(url, user, pass);

		final String sql = "SELECT Id, Name, LastModifiedDate FROM Account";
		final PreparedStatement stmt = conn.prepareStatement(sql);

		stmt.setFetchSize(200);
		stmt.getFetchSize();

		final ResultSet rs = stmt.executeQuery();
		while (rs.next()) {
			final String id = rs.getString("id");
			final String name = rs.getString("name");
			final java.sql.Date lastModifiedDate = rs.getDate("lastmodifieddate");
			if (false)
				System.err.println("id: " + id + ", name:" + name + ", LastModifiedDate:" + lastModifiedDate);
		}
		rs.close();
		stmt.close();
		conn.close();
	} catch (SQLException ex) {
		ex.printStackTrace();
		fail();
	}
}
 
Example 15
Project: MybatisGeneatorUtil   File: StringType2Handler.java   View Source Code Vote up 4 votes
@Override
public String getNullableResult(ResultSet rs, int columnIndex)
        throws SQLException {
    return rs.getString(columnIndex);
}
 
Example 16
Project: Ace   File: RankManager.java   View Source Code Vote up 4 votes
public static String getRankPrefix(Player player) throws SQLException {
    PreparedStatement stmt = plugin.getDb().getConnection().prepareStatement("SELECT prefix FROM ranks WHERE id = "+getRankId(player)+" LIMIT 1");
    ResultSet set = stmt.executeQuery();
    set.next();
    return set.getString("prefix");
}
 
Example 17
Project: blanco-sfdc-jdbc-driver   File: BlancoSfdcJdbcStatement1Test.java   View Source Code Vote up 4 votes
public void test001() throws Exception {
	if (BlancoSfdcJdbcTestConstants.isTestWithSfdc() == false)
		return;

	Class.forName("blanco.sfdc.jdbc.driver.BlancoSfdcJdbcDriver");
	try {
		final Properties prop = new Properties();
		final InputStream inStream = new FileInputStream("soqlro.properties");
		prop.load(new BufferedInputStream(inStream));
		inStream.close();

		final String url = prop.getProperty("url",
				"jdbc:blanco:sfdc:soqlro://login.salesforce.com/services/Soap/u/40.0");
		final String user = prop.getProperty("user", "NoUserSpesified");
		final String pass = prop.getProperty("password", "NoPassSpecified");

		final Connection conn = DriverManager.getConnection(url, user, pass);

		final Statement stmt = conn.createStatement();

		stmt.setFetchSize(200);
		stmt.getFetchSize();

		// final String sql = "SELECT Id, Name, LastModifiedDate FROM
		// Account";

		// final String sql = "select ApiVersion, Body, BodyCrc,
		// CreatedById, CreatedDate, Id, IsValid, LastModifiedById,
		// LastModifiedDate, LengthWithoutComments, Name, NamespacePrefix,
		// Status, SystemModstamp from ApexClass";

		final String sql = "SELECT Id, Name, LastModifiedDate FROM Contact";
		final ResultSet rs = stmt.executeQuery(sql);
		while (rs.next()) {
			final String id = rs.getString("id");
			final String name = rs.getString("name");
			final java.sql.Date lastModifiedDate = rs.getDate("LastModifiedDate");
			final java.sql.Timestamp lastModifiedDateTimestamp = rs.getTimestamp("LastModifiedDate");

			final String line = "id: " + id + ", name:" + name + ", LastModifiedDate:" + lastModifiedDate
					+ ", LastModifiedDate2:" + lastModifiedDateTimestamp;
		}
		rs.close();
		stmt.close();
		conn.close();

	} catch (SQLException ex) {
		System.out.println(ex.getMessage());
		ex.printStackTrace();
		fail();
	}
}
 
Example 18
Project: SugarOnRest   File: SchemaReader.java   View Source Code Vote up 4 votes
/**
 * Gets the table info of the schema.
 *
 * @param account The credential object.
 * @return Table object collection.
 */
public List<Table> getSchemaTables(Account account)  {
    List<Table> tables = new ArrayList<Table>();
    SqlQueryData queryData =  new SqlQueryData();

    try
    {
        ResultSet resultSet = DataAccess.getSchemaResultSet(account, queryData);
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();

        while (resultSet.next()) {
            String schema = resultSet.getString("TABLE_SCHEMA");
            String tableName = resultSet.getString("TABLE_NAME");
            String tableType = resultSet.getString("TABLE_TYPE");

            Table table = new Table();
            table.setName(tableName);
            table.setSchema(schema);

            String className = Utils.toPascalCase(tableName);
            table.setClassName(className);

            boolean isView = Utils.getIsView(tableType);
            table.setIsView(isView);

            List<Column> columns = getTableColumns(account, schema, tableName);
            table.setColumns(columns);

            List<String> uniquePackages = new ArrayList<String>();
            for (Column column : columns) {
                String packageName = Utils.getExtraPackage(column.getPropertyType());
                if (!packageName.equalsIgnoreCase("")) {
                    if (!uniquePackages.contains(packageName)) {
                        uniquePackages.add(packageName);
                    }
                }
            }

            table.setExtraPackages(uniquePackages);
            tables.add(table);
        }

    } catch (Exception e){
        queryData.closeResources();
        e.printStackTrace();
    }

    queryData.closeResources();
    return tables;
}
 
Example 19
Project: real-time-risk   File: InterestRateDAOImpl.java   View Source Code Vote up 3 votes
public InterestRate mapRow(ResultSet rs, int rowNum) throws SQLException {
    InterestRate.Builder builder = InterestRate.newBuilder();

    if (rs.getString("ccy_id") != null)
        builder.setCcyId(rs.getString("ccy_id"));

    builder.setValue(rs.getDouble("value"));

    if (rs.getTimestamp("timestamp") != null)
        builder.setTimestamp(rs.getTimestamp("timestamp").getTime());

    return builder.build();
}
 
Example 20
Project: parabuild-ci   File: jdbcDatabaseMetaData.java   View Source Code Vote up 1 votes
/**
 * Retrieves the name of this database product. <p>
 *
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information:</h3> <p>
 *
 * Starting with HSQLDB 1.7.2, this value is retrieved through an
 * SQL call to the new {@link Library#getDatabaseProductName} method
 * which allows correct determination of the database product name
 * for both local and remote database instances.
 * </div> <p>
 *
 * @return database product name
 * @exception SQLException if a database access error occurs
 */
public String getDatabaseProductName() throws SQLException {

    ResultSet rs =
        execute("call \"org.hsqldb.Library.getDatabaseProductName\"()");

    rs.next();

    String result = rs.getString(1);

    rs.close();

    return result;
}