com.sun.rowset.CachedRowSetImpl Java Examples

The following examples show how to use com.sun.rowset.CachedRowSetImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StringUtil.java    From OnlineFriend with Apache License 2.0 6 votes vote down vote up
/**
 * 将从数据库中取出的数据以表格形式显示
 * @param page 当前显示页
 * @param pageSize 每页显示记录数
 * @param rowSet 存储表中全部记录的行集对象
 * 
 * @return 表格格式化后的包含所有记录的StringBuffer
 * */
public static StringBuffer showMember(int page,int pageSize,CachedRowSetImpl rowSet){
	StringBuffer str = new StringBuffer();
	try {
		rowSet.absolute((page-1)*pageSize + 1);  //指向当前页的第一个元素
		for(int i=1;i<=pageSize;i++){
			str.append("<tr>");
			str.append("<td align=left>" + rowSet.getString(1) + "</td>");
			str.append("<td align=left>" + rowSet.getString(2) + "</td>");
			str.append("<td align=left>" + rowSet.getString(3) + "</td>");
			str.append("<td align=left>" + rowSet.getString(4) + "</td>");
			String imgString = "<img src=data/userfile/image/" + rowSet.getString(5) + " width=100 height=100/>";
			str.append("<td align=left>" + imgString + "</td>");
			str.append("</tr>");
			rowSet.next();
		}			
	} catch (Exception e) {
		// TODO: handle exception
	}
	
	return str;
}
 
Example #2
Source File: StringUtil.java    From OnlineFriend with Apache License 2.0 6 votes vote down vote up
/**
 * 显示文章列表
 * @param page 当前显示页
 * @param pageSize 每页显示记录数
 * @param rowSet 存储表中全部记录的行集对象
 * 
 * @return 表格格式化后的包含所有记录的StringBuffer
 * */
public static StringBuffer showArticleTitle(int page,int pageSize,CachedRowSetImpl rowSet){
	StringBuffer str = new StringBuffer();
	try {
		rowSet.absolute((page-1)*pageSize + 1);  //指向当前页的第一个元素
		str.append("<br>");
		for(int i=1;i<=pageSize;i++){
			str.append("<tr>");
			str.append("<td align=left><a href=ArticleShowContent?id=" + rowSet.getInt(1) + ">" + rowSet.getString(2) + "</a></td>");				
			str.append("</tr>");
			rowSet.next();
		}			
	} catch (Exception e) {
		// TODO: handle exception
	}
	
	return str;
}
 
Example #3
Source File: JdbcRowSetLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void createCachedRowSet_DeleteRecord_ThenCorrect() throws Exception {

    CachedRowSet crs = new CachedRowSetImpl();
    crs.setUsername(username);
    crs.setPassword(password);
    crs.setUrl(url);
    crs.setCommand(sql);
    crs.execute();
    crs.addRowSetListener(new ExampleListener());
    while (crs.next()) {
        if (crs.getInt("id") == 1) {
            System.out.println("CRS found customer1 and will remove the record.");
            crs.deleteRow();
            break;
        }
    }
}
 
Example #4
Source File: SyncService.java    From SQLite-sync.com with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void CommitSync(String syncId) {

        BinaryWriter binaryWriter = new BinaryWriter();
        tablesData = (CachedRowSetImpl) binaryWriter.readFromBinaryFile(SQLiteSyncConfig.WORKING_DIR + "SyncData/" + syncId + ".dat");

        String tableName = "";
        Integer tableId = 0;
        Connection cn = Database.getInstance().GetDBConnection();
        try {

            PreparedStatement query = cn.prepareStatement(QUERIES.COMMIT_SYNC());
            query.setInt(1, Integer.parseInt(syncId));
            ResultSet reader = query.executeQuery();
            while (reader.next()) {
                tableName = reader.getString("TableName");
                tableId = reader.getInt("TableId");
            }
        } catch (SQLException e) {
            Logs.write(Logs.Level.ERROR, "CommitSync() " + e.getMessage());
        } finally {
            JDBCCloser.close(cn);
        }


        UpdateSyncData(Integer.parseInt(syncId), tableName, tableId);
        SetSyncFinishMarker(syncId);
    }
 
Example #5
Source File: JdbcRowSetLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void createCachedRowSets_DoJoinRowSet_ThenCorrect() throws Exception {

    CachedRowSetImpl customers = new CachedRowSetImpl();
    customers.setUsername(username);
    customers.setPassword(password);
    customers.setUrl(url);
    customers.setCommand(sql);
    customers.execute();

    CachedRowSetImpl associates = new CachedRowSetImpl();
    associates.setUsername(username);
    associates.setPassword(password);
    associates.setUrl(url);
    String associatesSQL = "SELECT * FROM associates";
    associates.setCommand(associatesSQL);
    associates.execute();

    JoinRowSet jrs = new JoinRowSetImpl();
    final String ID = "id";
    final String NAME = "name";
    jrs.addRowSet(customers, ID);
    jrs.addRowSet(associates, ID);
    jrs.last();
    System.out.println("Total rows: " + jrs.getRow());
    jrs.beforeFirst();
    while (jrs.next()) {

        String string1 = jrs.getString(ID);
        String string2 = jrs.getString(NAME);
        System.out.println("ID: " + string1 + ", NAME: " + string2);
    }
}