本文整理汇总了Java中java.sql.ResultSet.last方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.last方法的具体用法?Java ResultSet.last怎么用?Java ResultSet.last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: sqlResultSetParse
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* 解析resultset中的条数
*
* @param resultSet
* @return
*/
private String sqlResultSetParse(ResultSet rset) {
try {
// 只能向前遍历的游标,只能用next()来遍历
if (rset.getType() == ResultSet.TYPE_FORWARD_ONLY) {
return "FORWARD_ONLY";
}
else {
// 可以滚动的游标,在用户使用游标之前,直接获取结果集大小,然后游标回到开始的地方(假装游标没有移动过)
rset.last();
int row = rset.getRow();
rset.beforeFirst();
return row + "";
}
}
catch (SQLException e) {
return e.toString();
}
}
示例3: initialize
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
try {
myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gui_assignment?autoReconnect=true&useSSL=false", "root", "root");
stmt = myConn.createStatement();
ResultSet rs = stmt.executeQuery("select Temperature_Reading from temp_values");
values = new int[rs.last() ? rs.getRow() : 0];
int[] temp = {10000,100000,500000};
noOfTempReadings = temp;
rs.setFetchDirection(ResultSet.FETCH_REVERSE);
rs.next();
int i = values.length-1;
while (rs.previous()) {
values[i--] = rs.getInt("Temperature_Reading");
}
} catch (SQLException e) {
e.printStackTrace();
System.err.println("DATABASE CONNECT ERROR");
System.exit(1);
}
System.out.println("No. of entries in database = "+values.length);
ObservableList<String> pivotValues = FXCollections.observableArrayList("n/2","n/4","n/6");
pivotSelect.setItems(pivotValues);
pivotSelect.setValue("n/2");
pivotSelect.setDisable(true);
ObservableList<Integer> baseValues = FXCollections.observableArrayList(2,10,16);
base.setItems(baseValues);
base.setValue(10);
base.setDisable(true);
btnViewGraph.setDisable(true);
}
示例4: DatabaseModel
import java.sql.ResultSet; //导入方法依赖的package包/类
DatabaseModel(ResultSet rs) {
try {
this.rs = rs;
if(rs==null) return;
cname = new String[rs.getMetaData().getColumnCount()];
for (int i = 0; i < cname.length; i++) {
cname[i] = rs.getMetaData().getColumnName(i+1);
}
rs.last();
nrow=rs.getRow();
} catch (SQLException ex) {
logger.error(ex.getMessage(),ex);
}
}
示例5: 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();
}
}
示例6: getUserName
import java.sql.ResultSet; //导入方法依赖的package包/类
public static String[] getUserName(String mailId) {
String[] name={"",""};
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String query = DBUtils.prepareSelectQuery(" * ",
"classroomflipkart.userdetail",
" emailId = '"+mailId+"' ",
"" );
try {
con = DBUtils.getConnection();
stmt = con.prepareStatement(query);
rs = stmt.executeQuery();
rs.last();
int size = rs.getRow();
if (size>0){
rs.beforeFirst();
rs.next();
name[0] = rs.getString("name");
name[1] = rs.getString("certifiedUser");
}
else
name[0] = "";
} catch (Exception e) {
name[0] = e.getMessage();
e.printStackTrace();
} finally {
DBUtils.closeAll(rs, stmt, con);
return name;
}
}
示例7: BBSThreadList
import java.sql.ResultSet; //导入方法依赖的package包/类
public static byte[] BBSThreadList(ResultSet rs, int start) throws SQLException {
final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.GUILD_BBS_PACKET.getValue());
mplew.write(0x06);
if (!rs.last()) {
mplew.write(0);
mplew.writeInt(0);
mplew.writeInt(0);
return mplew.getPacket();
}
int threadCount = rs.getRow();
if (rs.getInt("localthreadid") == 0) { //has a notice
mplew.write(1);
addThread(mplew, rs);
threadCount--; //one thread didn't count (because it's a notice)
} else {
mplew.write(0);
}
if (!rs.absolute(start + 1)) { //seek to the thread before where we start
rs.first(); //uh, we're trying to start at a place past possible
start = 0;
}
mplew.writeInt(threadCount);
mplew.writeInt(Math.min(10, threadCount - start));
for (int i = 0; i < Math.min(10, threadCount - start); i++) {
addThread(mplew, rs);
rs.next();
}
return mplew.getPacket();
}
示例8: getCategories
import java.sql.ResultSet; //导入方法依赖的package包/类
public static String[] getCategories() {
String[] category = {"ongoing"};
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String query = DBUtils.prepareSelectQuery(" * ",
"classroomflipkart.category",
"",
"GROUP BY category");
try {
con = DBUtils.getConnection();
stmt = con.prepareStatement(query);
rs = stmt.executeQuery();
rs.last();
int size = rs.getRow();
if (size>0){
rs.beforeFirst();
int count = 0;
category = new String[size];
while (rs.next())
category[count++] = rs.getString("category");
}
} catch (Exception e) {
category[0] = e.getMessage();
e.printStackTrace();
} finally {
DBUtils.closeAll(rs, stmt, con);
return category;
}
}
示例9: getSubCategories
import java.sql.ResultSet; //导入方法依赖的package包/类
public static String[] getSubCategories(String category) {
String[] subcategory ={"ongoing"};
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String query = DBUtils.prepareSelectQuery(" subcategory ",
"classroomflipkart.category",
" category = '"+category+"' ",
"" );
try {
con = DBUtils.getConnection();
stmt = con.prepareStatement(query);
rs = stmt.executeQuery();
rs.last();
int size = rs.getRow();
if (size>0){
rs.beforeFirst();
int count = 0;
subcategory = new String[size];
while (rs.next())
subcategory[count++] = rs.getString("subcategory");
}
} catch (Exception e) {
subcategory[0] = e.getMessage();
e.printStackTrace();
} finally {
DBUtils.closeAll(rs, stmt, con);
return subcategory;
}
}
示例10: isFavoriteExistes
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
*
* @param serverIp
* @param userServerId
* @param userId
* @return
*/
public Boolean isFavoriteExistes(String serverIp, String userServerId, String userId) {
Connection conn = JdbcHelper.getJdbcHelper().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
if(null != conn) {
String sql = "select m.* from myfavorites m where m.USERID=? and m.USERSERVERID=? and m.SERVERIP=?;";
ps = conn.prepareStatement(sql);
ps.setString(1, userId);
ps.setString(2, userServerId);
ps.setString(3, serverIp);
rs = ps.executeQuery();
if(null == rs)
return null;
rs.last();
System.out.println(rs.getRow());
if(0 < rs.getRow())
return true;
return false;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("sql state: " + e.getSQLState() +
" --> " + e.getStackTrace() + " -->" + e.getMessage());
return null;
}
return null;
}
示例11: 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);
}
示例12: 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;
}
示例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;
}
}
示例14: findByIds
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public List<App> findByIds(List<Integer> ids) {
// Session session = sessions.getCurrentSession();
// Query query = null;
// query =
// session.createQuery("select a.id, a.name, a.downLoadLink, a.logo from App a where id in (:ids)").setParameterList("ids",
// ids);
// List<App> list = HibernateHelper.list(query);
// for (App app : list) {
// changeOutputImpl.setUrls(app);
// }
StringBuilder tmp = new StringBuilder(ids.size() * 6);
for (Integer id : ids) {
tmp.append(id).append(',');
}
tmp.deleteCharAt(tmp.length() - 1);
String sql = appsByIds.replace("?", tmp.toString());
PreparedStatementCallback<List<App>> cb = new PreparedStatementCallback<List<App>>() {
@Override
public List<App> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
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 = appsRowMapper.mapRow(rs, rs.getRow());
changeOutputImpl.setUrls(app);
list.add(app);
}
return list;
} else {
return null;
}
} finally {
if (null != rs) {
rs.close();
}
}
}
};
return this.jdbcTemplate.execute(sql, cb);
}
示例15: 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;
}
}