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


Java ResultSet.first方法代码示例

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


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

示例1: findReviewByUserAndGame

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 *Method to find a review thanks to user and game
 *
 *@param utente user who made review
 *@param gioco reviewed game
 *@return Recensione searched review
 *@throws SQLException if no database connection is found or another error occurs
 */
 @Override
 public Recensione findReviewByUserAndGame(Utente utente, Gioco gioco) throws SQLException{
   Recensione recensione;
   Connection connection = DB.openConnection();
   PreparedStatement ps = connection.prepareStatement(FIND_REVIEW_BY_USER_AND_GAME);
   ps.setInt(1, utente.getId());
   ps.setInt(2, gioco.getId());
   ResultSet rset = ps.executeQuery();
   if ( rset.first() == false ) 
return null;
   recensione = new Recensione(rset.getInt(1), rset.getInt(2), rset.getString(3), rset.getInt(4), rset.getInt(5));
   ps.close();
   connection.close();
   return recensione;
 }
 
开发者ID:StefanoMartella,项目名称:GamingPlatform,代码行数:24,代码来源:RecensioneDao.java

示例2: testUser

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Test if the user name and password are correct.
 * @param username Name of the user.
 * @param password Password of the user.
 * @return True if the user is correct, false otherwise.
 */
private boolean testUser(String username, String password){
    try {
        PreparedStatement ps = ds.getConnection().prepareStatement(
                "SELECT COUNT(username) FROM session_table WHERE username LIKE ? AND password LIKE ?;");
        ps.setString(1, username);
        ps.setString(2, password);
        ResultSet rs = ps.executeQuery();
        rs.first();
        boolean isUser = rs.getInt(1) != 0;
        rs.close();
        return isUser;
    } catch (SQLException e) {
        LOGGER.error("Unable to request the database in order to test username/password.\n"+e.getLocalizedMessage());
        for(StackTraceElement el : e.getStackTrace()){
            LOGGER.error(el.toString());
        }
    }
    return false;
}
 
开发者ID:totone56,项目名称:orbis-lps2ima-dev,代码行数:26,代码来源:BaseServerImpl.java

示例3: reviewAlreadyMadeByUser

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
*Method to check if a user has already review a game
*
*@param utente user who reviews
*@param gioco reviewed game
*@return  boolean true if the user has already reviewed the game, false otherwise
*@throws SQLException if no database connection is found or another error occurs
*/
@Override
public boolean reviewAlreadyMadeByUser(Utente utente, Gioco gioco) throws SQLException{
  boolean already_reviewed = false;
  Connection connection = DB.openConnection();
  PreparedStatement ps = connection.prepareStatement(GAME_ALREADY_REVIEWED);
  ps.setInt(1, utente.getId());
  ps.setInt(2, gioco.getId());
  ResultSet rset = ps.executeQuery();
  rset.first();
  if( rset.getInt(1) == 1 )
      already_reviewed = true;
  ps.close();
  rset.close();
  connection.close();
  return already_reviewed;
}
 
开发者ID:StefanoMartella,项目名称:GamingPlatform,代码行数:25,代码来源:UtenteDao.java

示例4: getUser

import java.sql.ResultSet; //导入方法依赖的package包/类
public User getUser(User user) throws Exception {
    try {
        connect();            
        String sql = String.format("CALL get_user('%s', '%s', '%s');", user.getEmail(), user.getUserName(), user.getPassword());
        statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        if(resultSet.first()) {
            user.setId(resultSet.getInt("Id"));
            user.setEmail(resultSet.getString("Email"));
            user.setUserName(resultSet.getString("UserName"));
            user.setPassword("");
        } else {
            user = null;
        }
        disconnect();
        return user;
    } catch (Exception e) {
        throw new Exception("error occured while getting the user data!");
    }        
}
 
开发者ID:uclan-projects,项目名称:uclan-messanger,代码行数:21,代码来源:AuthenticationProvider.java

示例5: getUserWithUsername

import java.sql.ResultSet; //导入方法依赖的package包/类
public User getUserWithUsername(User newUser) throws Exception {
    try {
        connect();            
        String sql = String.format("SELECT * FROM Users WHERE UserName='%s'", newUser.getUserName());
        statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        User user = new User();
        if(resultSet.first()) {
            user.setId(resultSet.getInt("Id"));
            user.setEmail(resultSet.getString("Email"));
            user.setUserName(resultSet.getString("UserName"));
            user.setPassword("");
        } else {
            user = null;
        }
        disconnect();
        return user;
    } catch (Exception e) {
        throw new Exception("error occured while getting the user data!");
    }        
}
 
开发者ID:uclan-projects,项目名称:uclan-messanger,代码行数:22,代码来源:AuthenticationProvider.java

示例6: gameAlreadyVotedByUser

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
*Method to check if a user has already voted a game
*
*@param utente user who votes
*@param gioco voted game
*@return  boolean true if the user has already voted the game, false otherwise
*@throws SQLException if no database connection is found or another error occurs
*/
@Override
public boolean gameAlreadyVotedByUser(Utente utente, Gioco gioco) throws SQLException{
  boolean already_voted = false;
  Connection connection = DB.openConnection();
  PreparedStatement ps = connection.prepareStatement(GAME_ALREADY_VOTED);
  ps.setInt(1, utente.getId());
  ps.setInt(2, gioco.getId());
  ResultSet rset = ps.executeQuery();
  rset.first();
  if( rset.getInt(1) == 1 )
      already_voted = true;
  ps.close();
  rset.close();
  connection.close();
  return already_voted;
}
 
开发者ID:StefanoMartella,项目名称:GamingPlatform,代码行数:25,代码来源:UtenteDao.java

示例7: queryTool

import java.sql.ResultSet; //导入方法依赖的package包/类
public String queryTool(String toolSig, String column) {
Connection conn = getConnection();
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn
	    .prepareStatement("select " + column + " from lams_tool where tool_signature= \"" + toolSig + "\"");
    System.out.println("SQL stmt: " + stmt);
    results = stmt.executeQuery();

    if (results.first()) {
	return results.getString(column);

    }
} catch (SQLException se) {

    throw new DeployException("Could not get entry from lams_tool: " + column + "\n" + se.getMessage());

} finally {
    DbUtils.closeQuietly(stmt);
}
return "ERROR";
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:ToolDBUpdater.java

示例8: getFirstJoined

import java.sql.ResultSet; //导入方法依赖的package包/类
public String getFirstJoined(UUID uuid) {
	try {
		ResultSet resultset = table.select().where("uuid", uuid.toString()).execute();
		resultset.first();
		return resultset.getString("firstjoined");
	} catch (SQLException e) {
		return null;
	}
}
 
开发者ID:jusjus112,项目名称:OnlineChecker-Spigot-SQL-Support,代码行数:10,代码来源:SQLUtil.java

示例9: add

import java.sql.ResultSet; //导入方法依赖的package包/类
public Message add(Message message) throws Exception {
    try {
        connect();
        String sql;
        
        if(message.getId() <= 0) {
            sql = String.format("CALL add_message('%d', '%s', '%d');", message.getUserId(), message.getMessage(), message.getIsPublic() ? 1 : 0);
        } else {
            sql = String.format("CALL update_message('%d', '%s', '%d');", message.getId(), message.getMessage(), message.getIsPublic() ? 1 : 0);
        }
        
        statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        if(resultSet.first()) {
            message.setId(resultSet.getInt("Id"));
            message.setUserId(resultSet.getInt("UserId"));
            message.setMessage(resultSet.getString("Message"));
            message.setIsPublic(resultSet.getBoolean("IsPublic"));
        } else {
            message = null;
        }
        disconnect();
        return message;
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("error occured while saving the message data!");
    }
}
 
开发者ID:uclan-projects,项目名称:uclan-messanger,代码行数:29,代码来源:MessageProvider.java

示例10: findReviewById

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 *Method to find a review thanks to its id
 *
 *@param id review's id
 *@return Recensione searched review
 *@throws SQLException if no database connection is found or another error occurs
 */
 @Override
 public Recensione findReviewById(int id) throws SQLException{
   Recensione recensione;
   Connection connection = DB.openConnection();
   PreparedStatement ps = connection.prepareStatement(FIND_REVIEW);
   ps.setInt(1, id);
   ResultSet rset = ps.executeQuery();
   if ( rset.first() == false )
return null;
   recensione = new Recensione(rset.getInt(1), rset.getInt(2), rset.getString(3), rset.getInt(4), rset.getInt(5));
   ps.close();
   connection.close();
   return recensione;
 }
 
开发者ID:StefanoMartella,项目名称:GamingPlatform,代码行数:22,代码来源:RecensioneDao.java

示例11: prepareTable

import java.sql.ResultSet; //导入方法依赖的package包/类
public void prepareTable(H2Entity entity) throws H2PersistanceException {
	try {
		ResultSet result = connection.createStatement().executeQuery(String.format("SELECT * \n"
				+ "                 FROM INFORMATION_SCHEMA.TABLES \n"
				+ "                 WHERE TABLE_SCHEMA = 'PUBLIC' \n"
				+ "                 AND  TABLE_NAME = '%s'", entity.getTableName().toUpperCase()));
		if (!result.first()) {
			createTable(entity);
		}
	} catch (SQLException ex) {
		logger.log(Level.SEVERE,
				String.format("Cannot check if %s exists", entity.getTableName()), ex);
	}
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:15,代码来源:H2Persistance.java

示例12: setUserId

import java.sql.ResultSet; //导入方法依赖的package包/类
public void setUserId(String email) {
    ResultSet rs = connector.executeSelectStatement("SELECT id FROM users WHERE users.email LIKE '" + email + "'");
    try {
        rs.first();
        Main.setId(rs.getInt("id"));
    } catch (SQLException ex) {
        Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
    }
    
}
 
开发者ID:bartoszgajda55,项目名称:IP1,代码行数:11,代码来源:User.java

示例13: getCreateTableQuery

import java.sql.ResultSet; //导入方法依赖的package包/类
public static String getCreateTableQuery(String table,String srcPoolName, DBConfigInfo dbConfigInfo) {
	Connection srcConn = null;
	PreparedStatement srcPreStmt = null;
	String createTableQuery = null;
	QueryMaker qm = new QueryMaker("/src_mapper.xml");
	Map<String,Object> params = new HashMap<String,Object>();
	try {
		LogUtils.info("[START_CREATE_TABLE_QUERY_MAKE] "+table,DBUtils.class);
		srcConn = DBCPPoolManager.getConnection(srcPoolName);
		if(dbConfigInfo.DB_TYPE.equals(Constant.DB_TYPE.MYSQL)) {
			if(dbConfigInfo.SCHEMA_NAME!=null && !dbConfigInfo.SCHEMA_NAME.equals("")) {
				params.put("SCHEMA", dbConfigInfo.SCHEMA_NAME+".");
			} else {
				params.put("SCHEMA", "");
			}
			if(table!=null && !table.equals("")) {
				params.put("TABLE", table);
			} else {
				throw new Exception("TABLE NOT FOUND");
			}
			srcPreStmt = qm.getPreparedStatement("GET_CREATE_TABLE",Constant.DB_TYPE.MYSQL, params, srcConn, Double.parseDouble(dbConfigInfo.DB_VER));
			ResultSet rs = srcPreStmt.executeQuery();
			if(rs.first()) createTableQuery = rs.getString("Create Table");
			rs.close();
		}
		srcConn.close();
	} catch(Exception e){
		LogUtils.error(e.getMessage(),DBUtils.class);
	} finally {
		LogUtils.info("[END_CREATE_TABLE_QUERY_MAKE] "+table,DBUtils.class);
	}
	return createTableQuery;
}
 
开发者ID:experdb,项目名称:eXperDB-DB2PG,代码行数:34,代码来源:DBUtils.java

示例14: isResultSetClosedForTestBug69746

import java.sql.ResultSet; //导入方法依赖的package包/类
private boolean isResultSetClosedForTestBug69746(ResultSet resultSet) {
    try {
        resultSet.first();
    } catch (SQLException ex) {
        return ex.getMessage().equalsIgnoreCase(Messages.getString("ResultSet.Operation_not_allowed_after_ResultSet_closed_144"));
    }
    return false;
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:9,代码来源:ConnectionRegressionTest.java

示例15: find

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Find one item by id.
 *
 * @param id
 * @return
 */
@Override
public BestScoreBean find(long id)
{
    log.debug("Start method...");

    BestScoreBean obj = null;

    try
    {
        PreparedStatement prepared = DAOConnection.getInstance().prepareStatement(
                "SELECT * FROM best_scores WHERE id=?");

        prepared.setLong(1, id);

        ResultSet result = prepared.executeQuery();

        if (result.first())
        {
            obj = map(result);
        }

    } catch (SQLException e)
    {
        log.error("Error finding product : " + e);
    }

    log.debug("End method.");

    return obj;
}
 
开发者ID:nfriaa,项目名称:swing-memory-game,代码行数:37,代码来源:BestScoreRepository.java


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