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


Java ResultSet.isBeforeFirst方法代码示例

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


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

示例1: fromResultSet

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Create a table from a {@link ResultSet}.
 */
public static String fromResultSet(ResultSet resultSet) throws SQLException {
    if (resultSet == null) throw new NullPointerException("resultSet == null");
    if (!resultSet.isBeforeFirst()) throw new IllegalStateException("Result set not at first.");

    List<String> headers = new ArrayList<>();
    ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
    int columnCount = resultSetMetaData.getColumnCount();
    for (int column = 0; column < columnCount; column++) {
        headers.add(resultSetMetaData.getColumnName(column + 1));
    }

    List<String[]> data = new ArrayList<>();
    while (resultSet.next()) {
        String[] rowData = new String[columnCount];
        for (int column = 0; column < columnCount; column++) {
            rowData[column] = resultSet.getString(column + 1);
        }
        data.add(rowData);
    }

    String[] headerArray = headers.toArray(new String[headers.size()]);
    String[][] dataArray = data.toArray(new String[data.size()][]);
    return FlipTable.of(headerArray, dataArray);
}
 
开发者ID:freelifer,项目名称:limitjson,代码行数:28,代码来源:FlipTableConverters.java

示例2: topMacro

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Returns top macro and hits
 * @param guildId
 * @return Object array with index 0: hits 1: macro name 2: userid 3: fallback username
 * @throws NoMacroFoundException
 */
public static Object[] topMacro(String guildId) {
	Connection conn = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	try {
		conn = ConnectionPool.getConnection(guildId);
		stmt = conn.prepareStatement("SELECT hits, macro, user_id, user_created FROM `discord_macro` ORDER BY hits DESC LIMIT 1");
		rs = stmt.executeQuery();
		if(!rs.isBeforeFirst())
			return null;
		rs.next();
		return new Object[] {rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4)};
	} catch(SQLException e) {
		e.printStackTrace();
	} finally {
		SQLUtils.closeQuietly(rs);
		SQLUtils.closeQuietly(stmt);
		SQLUtils.closeQuietly(conn);
	}
	return null;
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:28,代码来源:MacroObject.java

示例3: Flight

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Constructor to auto load flight details from db
 *
 * @param flight_no
 */
public Flight(String flight_no) {
    this.conn = DBConnect.connect();
    PreparedStatement pst = null;
    try {
        String sql = "SELECT * FROM `flight` WHERE `flight_no` = ?";
        pst = conn.prepareStatement(sql);
        pst.setString(1, flight_no);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst()) {
            return;
        }
        while (rs.next()) {
            this.flight_no = rs.getString("flight_no");
            this.max_seats = rs.getInt("max_seats");
            this.airline_ID = rs.getString("airline_ID");
            this.active = rs.getBoolean("active");
            this.exist = true;
        }
    } catch (SQLException e) {
        System.out.println("Error : while excicuting prepared statement");
        System.out.println(e);
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:30,代码来源:Flight.java

示例4: Passenger

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * constructor with the id
 * @param passNo : passport number 
 */
public  Passenger(String passNo){
    conn = DBConnect.connect();
    PreparedStatement pst;
    try {
        String sql = "SELECT * FROM `passenger` WHERE `pass_no`=?";
        pst=conn.prepareStatement(sql);
        pst.setString(1,passNo);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst() ) {     
            return;
        } 
        while (rs.next()) {
                this.tel = rs.getString("tel");
                this.paddress = rs.getString("paddress");
                this.fname = rs.getString("fname");
                this.lname = rs.getString("lname");
                this.pass_no = rs.getString("pass_no");
                this.password = rs.getString("password");
                this.dob = rs.getDate("dob");
                this.active  = rs.getBoolean("active");
                this.exist = true;
        }
    } catch (SQLException e) {
        System.out.println("Error : while excicuting prepared statement");
        System.out.println(e);
        System.out.println(e.getErrorCode());
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:34,代码来源:Passenger.java

示例5: getBorrowedBookDetails

import java.sql.ResultSet; //导入方法依赖的package包/类
public BorrowedBookEntity getBorrowedBookDetails(int id) {
    try {
        ResultSet rs = connector.executeSelectStatement("SELECT borrowed_books.id, borrowed_books.date, borrowed_books.return_date, borrowed_books.fee_applied, "
            + "borrowed_books.user_id, borrowed_books.book_id, books.title, books.category, books.author, books.isbn, books.publisher FROM borrowed_books "
            + "INNER JOIN books ON borrowed_books.book_id = books.id WHERE borrowed_books.id LIKE " + id);
        if(rs.isBeforeFirst()) {
            rs.first();
            BorrowedBookEntity entity = new BorrowedBookEntity(rs.getInt("id"), rs.getInt("user_id"), rs.getInt("book_id"), rs.getString("title"), rs.getString("category"), rs.getString("author"),
                rs.getInt("isbn"), rs.getString("publisher"), rs.getDate("date"), rs.getDate("return_date"), rs.getInt("fee_applied"));
            return entity;
        }
        return null;
    } catch (SQLException ex) {
        Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
 
开发者ID:bartoszgajda55,项目名称:IP1,代码行数:18,代码来源:BorrowedBook.java

示例6: getDataId

import java.sql.ResultSet; //导入方法依赖的package包/类
public Integer getDataId(Connection c, String data) throws SQLException {
	if (cache.containsKey(data))
		return cache.get(data);
	
	ResultSet r = c.createStatement().executeQuery("SELECT id FROM " + tableName + " WHERE " + dataRowName + " = '" + data + "'");
	if (!r.isBeforeFirst()) {
		c.createStatement().executeUpdate("INSERT INTO " + tableName + " (" + dataRowName + ") VALUES ('" + data + "');");
		r = c.createStatement().executeQuery("SELECT id FROM " + tableName + " WHERE " + dataRowName + " = '" + data + "'");
	}
	r.next();
	
	int result = r.getInt("id");
	r.close();
	
	cache.put(data, result);
	return result;
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:18,代码来源:DataCache.java

示例7: searchForName

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Search for a macro by name given the guild ID
 * @param name Name to wildcard
 * @param guildId GuildID to search in
 * @return Null if no results, populated string array of macro names if results
 */
public static String[] searchForName(String name, String guildId) {
	Connection conn = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	ArrayList<String> toReturn = new ArrayList<String>(10);
	try {
		conn = ConnectionPool.getConnection(guildId);
		String sql = "SELECT macro FROM `discord_macro` WHERE macro LIKE ?";
		stmt = conn.prepareStatement(sql);
		stmt.setString(1, "%" + name + "%");
		rs = stmt.executeQuery();
		if(!rs.isBeforeFirst())
			return null;
		while(rs.next()) {
			toReturn.add(rs.getString(1));
		}
		return toReturn.toArray(new String[0]);
	} catch(SQLException e) {
		e.printStackTrace();
		return null;
	} finally {
		SQLUtils.closeQuietly(rs);
		SQLUtils.closeQuietly(stmt);
		SQLUtils.closeQuietly(conn);
	}

}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:34,代码来源:MacroObject.java

示例8: forName

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Get and return a macro for given macroName
 * If found, increment the hits
 * @param name Macro name to search for
 * @param guildId Guild ID to search in
 * @return Macro if found
 * @throws NoMacroFoundException if no macro is found
 */
public static MacroObject forName(String name, String guildId, boolean hit) throws IllegalArgumentException {
	Connection conn = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	try {
		conn = ConnectionPool.getConnection(guildId);
		String sql = "SELECT user_created, date_created, content, hits, user_id FROM `discord_macro` WHERE macro = ?";
		stmt = conn.prepareStatement(sql);
		stmt.setString(1, name.toLowerCase());
		rs = stmt.executeQuery();
		if(!rs.isBeforeFirst()) {
			throw new IllegalArgumentException("No macro found for " + name);
		}
		rs.next();
		if(hit) {
			sql = "UPDATE `discord_macro` SET hits = hits+1 WHERE macro = ?";
			PreparedStatement stmt2 = conn.prepareStatement(sql);
			stmt2.setString(1, name.toLowerCase());
			stmt2.execute();
			SQLUtils.closeQuietly(stmt2);
		}
		return new MacroObject(rs.getString(1), name, rs.getString(3), rs.getInt(4), rs.getString(5),
				guildId, LocalDate.parse(rs.getObject(2).toString()));
	} catch(SQLException e) {
		e.printStackTrace();
	} finally {
		SQLUtils.closeQuietly(rs);
		SQLUtils.closeQuietly(stmt);
		SQLUtils.closeQuietly(conn);
	}
	return null;
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:41,代码来源:MacroObject.java

示例9: Tickets

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * 
 * @param psNo
 * @param Plegno 
 */
public Tickets(int psNo, int Plegno) {
    conn = DBConnect.connect();
    PreparedStatement pst = null;
    try {
        String sql = "SELECT * FROM `tickets` WHERE `seat_no`=? AND `leg_no`=?";
        pst = conn.prepareStatement(sql);
        pst.setInt(1, psNo);
        pst.setInt(2, Plegno);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst()) {
            return;
        }
        while (rs.next()) {
            this.seat_no = rs.getInt("seat_no");
            this.pass_no = rs.getString("pass_no");
            this.leg_no = rs.getInt("leg_no");
            this.class_ = rs.getInt("class");
            this.exist = true;
        }

    } catch (SQLException e) {
        System.out.println("Error:" + e);

    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:32,代码来源:Tickets.java

示例10: Admin

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * constructor with the id
 * @param adminid : admin id
 */
public  Admin(int adminid){
    conn = DBConnect.connect();
    PreparedStatement pst;
    try {
        String sql = "SELECT * FROM `admin` WHERE `admin_id` = ?";
        pst=conn.prepareStatement(sql);
        pst.setInt(1,adminid);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst() ) {     
            return;
        } 
        while (rs.next()) {
                this.admin_id =rs.getInt("admin_id");
                this.password = rs.getString("password");
                this.user_name = rs.getString("user_name");
                this.admin_level = rs.getInt("admin_level");
                this.name = rs.getString("name");
                this.exist = true;
        }
    } catch (SQLException e) {
        System.out.println("Error : while excicuting prepared statement");
        System.out.println(e);
        System.out.println(e.getErrorCode());
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:31,代码来源:Admin.java

示例11: adminLogin

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * constructor with the id
 * @param username : user name of admin
 * @param pass : admin password 
 * @return  : boolian login details validity
 */
public boolean adminLogin(String username,String pass){
    conn = DBConnect.connect();
    PreparedStatement pst;
    try {
        String sql = "SELECT * FROM `admin` WHERE `user_name` = ? AND `password` = ?";
        pst=conn.prepareStatement(sql);
        pst.setString(1,username);
        pst.setString(2, pass);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst() ) {     
            return false;
        } 
        while (rs.next()) {
                this.admin_id =rs.getInt("admin_id");
                this.password = rs.getString("password");
                this.user_name = rs.getString("user_name");
                this.admin_level = rs.getInt("admin_level");
                this.name = rs.getString("name");
                this.exist = true;
                return true;
        }
        return false;
    } catch (SQLException e) {
        System.out.println("Error : while excicuting prepared statement");
        System.out.println(e);
        System.out.println(e.getErrorCode());
        return false;
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:37,代码来源:Admin.java

示例12: FlightLeg

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Constructor to auto load flight leg from db
 * @param leg_no : primary key of Flight leg
 */
public FlightLeg(int leg_no)
{
  this.conn = DBConnect.connect(); 
  PreparedStatement pst = null;
    try {
        String sql = "SELECT * FROM `flight_leg` WHERE `leg_no` = ?";
        pst=conn.prepareStatement(sql);
        pst.setInt(1,leg_no);
        ResultSet rs;
        rs = pst.executeQuery();
        if (!rs.isBeforeFirst() ) {     
            return;
        } 
        while (rs.next()) {
            this.leg_no = rs.getInt("leg_no");
            this.leg_type = rs.getString("leg_type");
            this.from_aID = rs.getString("from_aID");
            this.to_aID = rs.getString("to_aID");
            this.departure_time = rs.getTimestamp("departure_time");
            this.arival_time = rs.getTimestamp("arival_time");
            this.flight_no = rs.getString("flight_no");
            this.exist = true;
        }
    } catch (SQLException e) {
        System.out.println("Error : while excicuting prepared statement");
        System.out.println(e);
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:33,代码来源:FlightLeg.java

示例13: searchByUser

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Search for macros by user and given guild
 * @param userId UserID to search for
 * @param guildId GuildID to search in
 * @return Null if no results, populated string array of macro names if results
 */
public static String[] searchByUser(String userId, String guildId) {
	Connection conn = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	ArrayList<String> toReturn = new ArrayList<String>(10);
	try {
		conn = ConnectionPool.getConnection(guildId);
		String sql = "SELECT macro FROM `discord_macro` WHERE user_id = ?";
		stmt = conn.prepareStatement(sql);
		stmt.setString(1, userId);
		rs = stmt.executeQuery();
		if(!rs.isBeforeFirst())
			return null;
		while(rs.next()) {
			toReturn.add(rs.getString(1));
		}
		return toReturn.toArray(new String[0]);
	} catch(SQLException e) {
		e.printStackTrace();
		return null;
	} finally {
		SQLUtils.closeQuietly(rs);
		SQLUtils.closeQuietly(stmt);
		SQLUtils.closeQuietly(conn);
	}
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:33,代码来源:MacroObject.java

示例14: Airport

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * 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);
        
    }
}
 
开发者ID:YasasshraSolutions,项目名称:Java-Air-Reservation,代码行数:31,代码来源:Airport.java

示例15: getRequestedBookDetails

import java.sql.ResultSet; //导入方法依赖的package包/类
public RequestedBookEntity getRequestedBookDetails(int id) {
    try {
        ResultSet rs = connector.executeSelectStatement("SELECT requested_books.id, requested_books.date, requested_books.user_id, requested_books.book_id, "
            + "books.title, books.category, books.author, books.isbn, books.publisher FROM requested_books INNER JOIN "
            + "books ON requested_books.book_id = books.id WHERE requested_books.id LIKE " + id);
        if(rs.isBeforeFirst()) {
            rs.next();
            return new RequestedBookEntity(rs.getInt("id"), rs.getInt("user_id"), rs.getInt("book_id"), rs.getString("title"), rs.getString("category"), rs.getString("author"),
                rs.getInt("isbn"), rs.getString("publisher"), rs.getDate("date"));
        }
    } catch (SQLException ex) {
        Logger.getLogger(RequestedBook.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
 
开发者ID:bartoszgajda55,项目名称:IP1,代码行数:16,代码来源:RequestedBook.java


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