當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。