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


Java ResultSet.beforeFirst方法代码示例

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


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

示例1: displayResults

import java.sql.ResultSet; //导入方法依赖的package包/类
protected int displayResults(ResultSet rs) throws SQLException {
    int rows = 0;
    ResultSetMetaData rsmd = rs.getMetaData();
    int cols = rsmd.getColumnCount();
    if (rs != null) {
        rs.beforeFirst();
        while (rs.next()) {
            rows++;

            for (int i = 0; i < cols; i++) {
                System.out.print(rs.getString(i + 1) + " ");
            }
            System.out.println();
        }
    }

    return rows;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:CommonRowSetTests.java

示例2: handleResultSet

import java.sql.ResultSet; //导入方法依赖的package包/类
private void handleResultSet(List<Map<String, Object>> list, ResultSet resultSet) {
    try {
        if (resultSet != null && resultSet.last()) {
            resultSet.beforeFirst();
            ResultSetMetaData rsmd = resultSet.getMetaData();
            while (resultSet.next()) {
                Map<String, Object> map = Maps.newHashMap();
                for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                    map.put(rsmd.getColumnName(i), resultSet.getString(i));
                }
                list.add(map);
            }
            resultSet.beforeFirst();
            resultSet.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:DreamYa0,项目名称:zeratul,代码行数:20,代码来源:SqlTools.java

示例3: printResults

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Prints the supplied results to the console
 * 
 * @param results
 *            ResultSet results from database query
 * @throws SQLException
 *             unable to get query results
 */
private void printResults(ResultSet results) throws SQLException {

	if (!results.next()) {
		System.out.println("\tDatabase Empty");
	} else {
		System.out.println("\t#\tScore:\t\tTitle:");
		System.out.println("\t---\t----------\t----------------------");
		int place = 1;
		results.beforeFirst();
		while (results.next()) {
			System.out.println("\t" + place++ + "\t" + results.getDouble("averageReadability") + "\t\t"
					+ results.getString("title"));
		}
	}
}
 
开发者ID:rossweinstein,项目名称:text-readability-analyzer,代码行数:24,代码来源:DBInteract.java

示例4: showGuildRanks

import java.sql.ResultSet; //导入方法依赖的package包/类
public static byte[] showGuildRanks(int npcid, ResultSet rs) throws SQLException {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.GUILD_OPERATION.getValue());
    mplew.write(0x49);
    mplew.writeInt(npcid);
    if (!rs.last()) { //no guilds o.o
        mplew.writeInt(0);
        return mplew.getPacket();
    }
    mplew.writeInt(rs.getRow()); //number of entries
    rs.beforeFirst();
    while (rs.next()) {
        mplew.writeMapleAsciiString(rs.getString("name"));
        mplew.writeInt(rs.getInt("GP"));
        mplew.writeInt(rs.getInt("logo"));
        mplew.writeInt(rs.getInt("logoColor"));
        mplew.writeInt(rs.getInt("logoBG"));
        mplew.writeInt(rs.getInt("logoBGColor"));
    }
    return mplew.getPacket();
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:22,代码来源:MaplePacketCreator.java

示例5: WebRowSetTest0006

import java.sql.ResultSet; //导入方法依赖的package包/类
@Test(dataProvider = "rowsetUsingCoffees")
public void WebRowSetTest0006(WebRowSet wrs) throws Exception {
    ResultSet rs = wrs;
    rs.beforeFirst();
    ByteArrayOutputStream baos = writeWebRowSetWithOutputStreamWithWriter(rs);
    try (WebRowSet wrs1 = readWebRowSetWithOInputStreamWithReader(baos)) {
        assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
        assertEquals(wrs1.size(), COFFEES_ROWS);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:CommonWebRowSetTests.java

示例6: getAppDefultRank

import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public List<App> getAppDefultRank(final int typeId, final int top) {
    PreparedStatementCallback<List<App>> cb = new PreparedStatementCallback<List<App>>() {
        @Override
        public List<App> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setInt(1, typeId);
            ps.setInt(2, top);
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                if (rs.last()) {
                    int count = rs.getRow();
                    List<App> list = new ArrayList<App>(count);
                    rs.beforeFirst();
                    App app = null;
                    while (rs.next()) {
                        app = appRowMapper.mapRow(rs, rs.getRow());
                        changeOutputImpl.setUrls(app);
                        list.add(app);
                    }
                    return list;
                }

            } catch (Exception e) {
                logger.error("SQL data error:", e);
                return null;
            } finally {
                if (null != rs)
                    rs.close();
            }
            return null;
        }
    };
    return jdbcTemplate.execute(QUERY_APP_DEFAULT_TOP_SQL, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:36,代码来源:AppRankDaoImpl.java

示例7: getAppTypes

import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public List<AppType> getAppTypes(final int parentId) {
    PreparedStatementCallback<List<AppType>> cb = new PreparedStatementCallback<List<AppType>>() {
        @Override
        public List<AppType> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ResultSet rs = null;
            try {
                ps.setInt(1, parentId);
                ps.setInt(2, parentId);
                rs = ps.executeQuery();
                // predicate count.
                if (rs.last()) {
                    int count = rs.getRow();
                    List<AppType> list = new ArrayList<AppType>(count);
                    rs.beforeFirst();
                    AppType appType = null;
                    while (rs.next()) {
                        appType = appTypeRowMapper.mapRow(rs, rs.getRow());
                        list.add(appType);
                    }
                    return list;
                } else {
                    return null;
                }
            } finally {
                if (null != rs) {
                    rs.close();
                }
            }
        }
    };
    return this.jdbcTemplate.execute(appTypes, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:34,代码来源:AppsDaoImpl.java

示例8: getAppCategoryRank

import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public List<App> getAppCategoryRank(final int parentId, final int subCatalog, final int top) {
    PreparedStatementCallback<List<App>> cb = new PreparedStatementCallback<List<App>>() {
        @Override
        public List<App> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setInt(1, parentId);
            ps.setInt(2, subCatalog);
            ps.setInt(3, top);
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                if (rs.last()) {
                    int count = rs.getRow();
                    List<App> list = new ArrayList<App>(count);
                    rs.beforeFirst();
                    App app = null;
                    while (rs.next()) {
                        app = appRowMapper.mapRow(rs, rs.getRow());
                        changeOutputImpl.setUrls(app);
                        list.add(app);
                    }
                    return list;
                }

            } catch (Exception e) {
                logger.error("SQL data error:", e);
                return null;
            } finally {
                if (null != rs)
                    rs.close();
            }
            return null;
        }
    };
    return jdbcTemplate.execute(QUERY_APP_CATEGORY_TOP_SQL, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:AppRankDaoImpl.java

示例9: assertResultSetLength

import java.sql.ResultSet; //导入方法依赖的package包/类
protected void assertResultSetLength(ResultSet rset, int len) throws Exception {
    int oldRowPos = rset.getRow();
    rset.last();
    assertEquals("Result set length", len, rset.getRow());
    if (oldRowPos > 0) {
        rset.absolute(oldRowPos);
    } else {
        rset.beforeFirst();
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:11,代码来源:BaseTestCase.java

示例10: doQuery

import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public ResultSet doQuery(final SqlContext sqlContext, final PreparedStatement preparedStatement,
		final ResultSet resultSet) {
	// カウント初期値
	int rowCount = -1;
	try {
		// resultSetのカーソル種別を取得
		// 種別「TYPE_FORWARD_ONLY」の場合、beforeFirstメソッドが効かないため除外
		if (resultSet.getType() != ResultSet.TYPE_FORWARD_ONLY) {
			// 件数結果取得
			resultSet.last();
			rowCount = resultSet.getRow();
			resultSet.beforeFirst();
		}
	} catch (SQLException e) {
		// ここでの例外は実処理に影響を及ぼさないよう握りつぶす
	}

	String userName = getParam(sqlContext, USER_NAME_KEY);
	if (userName == null) {
		// ユーザ名が設定されていない時
		userName = DEFAULT_USER_NAME;
	}

	String funcId = getParam(sqlContext, FUNC_ID_KEY);
	if (funcId == null) {
		// 機能IDが設定されていない時
		funcId = DEFAULT_FUNC_ID;
	}

	LOG.debug(ToStringBuilder.reflectionToString(
			new AuditData(userName, funcId, sqlContext.getSqlId(), sqlContext.getSqlName(), sqlContext
					.getExecutableSql(), rowCount), ToStringStyle.JSON_STYLE));

	return resultSet;
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:37,代码来源:AuditLogSqlFilter.java

示例11: getPrimaryKeys

import java.sql.ResultSet; //导入方法依赖的package包/类
protected Object[] getPrimaryKeys(ResultSet rs) throws SQLException {
    List<? super Object> result = new ArrayList<>();
    if (rs == null) {
        return null;
    }
    rs.beforeFirst();
    while (rs.next()) {
        result.add(rs.getInt(1));
    }
    return result.toArray();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:CommonRowSetTests.java

示例12: WebRowSetTest0004

import java.sql.ResultSet; //导入方法依赖的package包/类
@Test(dataProvider = "rowsetUsingCoffees")
public void WebRowSetTest0004(WebRowSet wrs) throws Exception {
    ResultSet rs = wrs;
    rs.beforeFirst();
    ByteArrayOutputStream baos = writeWebRowSetWithOutputStream(rs);
    try (WebRowSet wrs1 = readWebRowSetWithOInputStream(baos)) {
        assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
        assertEquals(wrs1.size(), COFFEES_ROWS);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:CommonWebRowSetTests.java

示例13: dbLoginCheck

import java.sql.ResultSet; //导入方法依赖的package包/类
public static String[] dbLoginCheck(String emailId, String password) {
    Connection con = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    String userID = getMotherboardSN.getMotherboardSN();

    String query = DBUtils.prepareSelectQuery(" * ", "classroomflipkart.userdetail", "( emailId = ? AND password = ? )");

    String updateCurrentUserQuery = DBUtils.prepareInsertQuery("classroomflipkart.currentuser", "id, name, emailId", "?,?,?");

    String[] status = {"ongoing",""};

    try {
        con = DBUtils.getConnection();
        stmt = con.prepareStatement(query);
        stmt.setString(1, emailId);
        stmt.setString(2, password);

        rs = stmt.executeQuery();
        rs.last();
        int size = rs.getRow();
        rs.beforeFirst();

        if (size>0){
            status[0]="success";
            rs.next();
            status[1]=rs.getString("name");

            stmt = con.prepareStatement(updateCurrentUserQuery);
            stmt.setString(1, userID);
            stmt.setString(2, status[1]);
            stmt.setString(3, emailId);
            stmt.executeUpdate();
        }

    } catch (Exception e) {
        e.printStackTrace();
        status[0] = e.getMessage();
    } finally {
        DBUtils.closeAll(rs, stmt, con);
        return status;
    }
}
 
开发者ID:madHEYsia,项目名称:ClassroomFlipkart,代码行数:45,代码来源:dbLoginCheck.java

示例14: productbyType

import java.sql.ResultSet; //导入方法依赖的package包/类
public static BorderPane productbyType(String type) {

        BorderPane products = new BorderPane();
        products.setPadding(new Insets(10,20,10,20));

        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;

        String query = DBUtils.prepareSelectQuery(" * ",
                " classroomflipkart.productdetail AS T ," +
                        " ( "+ DBUtils.prepareSelectQuery("productId",
                                " classroomflipkart.homeproducts ",
                                "type = '"+type+"'")+
                        " ) AS S",
                " T.productId = S.productId ");

        try {
            con = DBUtils.getConnection();
            stmt = con.prepareStatement(query);
            rs = stmt.executeQuery();

            rs.last();
            int size = rs.getRow();

            if (size>0){
                rs.beforeFirst();

                Label title = new Label(type+"");
                title.setFont(Font.font("Open Sans", FontWeight.BOLD,17));
                title.setPadding(new Insets(10));
                title.setAlignment(Pos.CENTER);

                HBox productList = new HBox(20);
                productList.setAlignment(Pos.CENTER);

                while (rs.next()) {
                    String productId = rs.getString("productId");
                    String productName = rs.getString("productName");
                    String newPrice = rs.getString("newPrice");
                    String oldPrice = rs.getString("oldPrice");
                    String category = rs.getString("category");
                    String subcategory = rs.getString("subcategory");
                    String imageName = rs.getString("imageName");
                    String productAvailability = rs.getString("productAvailability");

                    productList.getChildren().add(productDetail.productByType(productId,productName,newPrice,oldPrice,category,subcategory,imageName, productAvailability));
                }

                ScrollPane proScroller = new ScrollPane(productList);
                proScroller.setFitToHeight(true);
                proScroller.setFitToWidth(true);
                proScroller.setPannable(true);
                proScroller.setPadding(new Insets(0,0,30,0));

                StackPane titlePane = new StackPane(title);
                titlePane.setAlignment(Pos.CENTER);

                StackPane productPane = new StackPane(proScroller);
                productPane.setAlignment(Pos.CENTER);

                products.setTop(titlePane);
                products.setCenter(productPane);
            }


        } catch (Exception e) {
            products.setCenter(new Label(e.getMessage()));
            e.printStackTrace();
        } finally {
            DBUtils.closeAll(rs, stmt, con);
            return products;
        }
    }
 
开发者ID:madHEYsia,项目名称:ClassroomFlipkart,代码行数:75,代码来源:fetchProducts.java

示例15: testDeletable2

import java.sql.ResultSet; //导入方法依赖的package包/类
public void testDeletable2() {

        try {
            Connection c =
                DriverManager.getConnection("jdbc:hsqldb:mem:mytestdb", "SA",
                                            "");
            String createSQL =
                "create table test (num INTEGER PRIMARY KEY, str VARCHAR(25))";
            Statement createStmt = c.createStatement();

            createStmt.execute(createSQL);
            createStmt.close();

            String            ins = "insert into test (num,str) values (?,?)";
            PreparedStatement pStmt = c.prepareStatement(ins);

            for (int i = 0; i < 100; i++) {
                pStmt.setInt(1, i);
                pStmt.setString(2, "String" + i);
                pStmt.execute();
            }

            // there should now be 100 rows in the table
            String select = "SELECT * FROM test";
            PreparedStatement stmt = c.prepareStatement(select,
                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet rs = stmt.executeQuery();

            rs.beforeFirst();

            while (rs.next()) {
                int num = rs.getInt("num");

                if ((num % 7) == 0) {
                    System.out.println("Deleting row:" + num);
                    rs.deleteRow();
                }
            }

            Statement dropStmt = c.createStatement();

            dropStmt.execute("drop table test;");
            dropStmt.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:48,代码来源:TestUpdatableResultSets.java


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