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