本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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!");
}
}
示例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!");
}
}
示例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;
}
示例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";
}
示例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;
}
}
示例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!");
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}