⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollcursors2.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		rs = s_f_r.executeQuery("values 1, 2, 3, 4, 5, 6");		if (rs == null)		{			System.out.println("rs expected to be non-null.");			passed = false;		}		// Iterate straight thru RS, expect only 5 rows.		for (int index = 1; index < 6; index++)		{			if (! rs.next())			{				System.out.println("rs.next() failed, index = " + index);				passed = false;				break;			}		}		// We should not see another row (only 5, not 6)		if (rs.next())		{			System.out.println("rs.next() failed, should not have seen 6th row.");			passed = false;		}		rs.close();		s_f_r.close();		return passed;	}	/**	 * Scroll sensitive cursor tests	 *	 * This method tests scroll sensitive cursors.	 * (Not implemented, so we should get back	 * scroll insensitive curors with read only concurrency.) 	 *	 * @param conn	The Connection	 *	 * @return	true if it succeeds, false if it doesn't	 *	 * @exception SQLException	Thrown if some unexpected error happens	 */	static boolean scrollSensitiveTest( Connection conn)		throws SQLException 	{		ResultSet	rs;		SQLWarning	warning;		Statement	s_s_r = null; // sensitive, read only		Statement	s_s_u = null; // sensitive, updatable		s_s_r = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,									 ResultSet.CONCUR_READ_ONLY);		// We should have gotten a warning and a scroll insensitive cursor		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();		}		conn.clearWarnings();		// Verify that result set from statement is 		// scroll insensitive and read only		rs = s_s_r.executeQuery("select * from t");		if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)		{			System.out.println("cursor type = " + rs.getType() +							   ", not " + ResultSet.TYPE_SCROLL_INSENSITIVE);		}		if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)		{			System.out.println("concurrency = " + rs.getConcurrency() +							   ", not " + ResultSet.CONCUR_READ_ONLY);		}		rs.close();		// Close the statement		s_s_r.close();		s_s_u = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,									 ResultSet.CONCUR_UPDATABLE);		// We should have gotten 2 warnings and a read only scroll insensitive cursor		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();		}		conn.clearWarnings();		// Verify that result set from statement is 		// scroll insensitive and read only		rs = s_s_u.executeQuery("select * from t");		if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)		{			System.out.println("cursor type = " + rs.getType() +							   ", not " + ResultSet.TYPE_SCROLL_INSENSITIVE);		}		if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)		{			System.out.println("concurrency = " + rs.getConcurrency() +							   ", not " + ResultSet.CONCUR_READ_ONLY);		}		rs.close();		return true;	}	/** 	 * Positive tests for scroll insensitive cursor.	 *	 * @param conn	The connection to use.	 *	 * @return	Whether or not we were successful.	 *	 * @exception SQLException	Thrown if some unexpected error happens	 */	static boolean scrollInsensitivePositive( Connection conn)		throws SQLException 	{		boolean 	passed = true;		PreparedStatement ps_i_r = null;		PreparedStatement ps_i_u = null;		ResultSet	rs;		SQLWarning	warning;		Statement	s_i_r = null; // insensitive, read only		Statement	s_i_u = null; // insensitive, updatable		s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,									 ResultSet.CONCUR_READ_ONLY);		// We should not have gotten any warnings 		// and should have gotten a scroll insensitive cursor		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("unexpected warning = " + warning);			warning = warning.getNextWarning();			passed = false;		}		conn.clearWarnings();		// run a query		rs = s_i_r.executeQuery("select * from t");		// verify scroll insensitive and read only		if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)		{			System.out.println(				"rs.getType() expected to return TYPE_SCROLL_INSENSITIVE, not " +				rs.getType());			passed = false;		}		if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)		{			System.out.println(				"rs.getConcurrency() expected to return CONCUR_READ_ONLY, not " +				rs.getConcurrency());			passed = false;		}				// We should be positioned before the 1st row		if (! rs.isBeforeFirst())		{			System.out.println("expected to be before the 1st row");			passed = false;		}                if (rs.absolute(0))                {			System.out.println("absolute(0) expected to return false");			passed = false;                }		if (! rs.isBeforeFirst())		{			System.out.println("still expected to be before the 1st row");			passed = false;		}		// go to first row		if (! rs.first())		{			System.out.println("expected first() to succeed");			passed = false;		}		if (rs.getInt(1) != 2)		{			System.out.println(				"rs.getInt(1) expected to return 2, not " + rs.getInt(1));			passed = false;		}		if (! rs.isFirst())		{			System.out.println("expected to be on the 1st row");			passed = false;		}		// move to before first		rs.beforeFirst();		if (! rs.isBeforeFirst())		{			System.out.println("expected to be before the 1st row");			passed = false;		}		// move to last row		if (! rs.last())		{			System.out.println("expected last() to succeed");			passed = false;		}		if (! rs.isLast())		{			System.out.println("expected to be on the last row");			passed = false;		}		if (rs.isAfterLast())		{			System.out.println("not expected to be after the last row");			passed = false;		}		if (rs.getInt(1) != 6)		{			System.out.println(				"rs.getInt(1) expected to return 6, not " + rs.getInt(1));			passed = false;		}		if (rs.next())		{			System.out.println("not expected to find another row");			passed = false;		}		if (! rs.isAfterLast())		{			System.out.println("expected to be after the last row");			passed = false;		}		// We're after the last row, verify that only isAfterLast()		// returns true		if (rs.isLast())		{			System.out.println("not expected to be on the last row");			passed = false;		}		if (rs.isFirst())		{			System.out.println("not expected to be on the first row");			passed = false;		}		if (rs.isBeforeFirst())		{			System.out.println("not expected to be before the first row");			passed = false;		}		// get/setFetchDirection()		if (rs.getFetchDirection() != ResultSet.FETCH_FORWARD)		{			System.out.println(				"getFetchDirection() expected to return FETCH_FORWARD, not " +				rs.getFetchDirection());			passed = false;		}		rs.setFetchDirection(ResultSet.FETCH_UNKNOWN);		if (rs.getFetchDirection() != ResultSet.FETCH_UNKNOWN)		{			System.out.println(				"getFetchDirection() expected to return FETCH_UNKNOWN, not " +				rs.getFetchDirection());			passed = false;		}		// get/setFetchSize()		if (rs.getFetchSize() != 1)		{			System.out.println(				"getFetchSize() expected to return 1, not " + rs.getFetchSize());			passed = false;		}		rs.setFetchSize(5);		if (rs.getFetchSize() != 5)		{			System.out.println(				"getFetchSize() expected to return 5, not " + rs.getFetchSize());			passed = false;		}		// setFetchSize() to 0 should have no effect.		rs.setFetchSize(0);		if (rs.getFetchSize() != 5)		{			System.out.println(				"getFetchSize() expected to return 5, not " + rs.getFetchSize());			passed = false;		}		// done		rs.close();		// Scroll insensitive and updatable		s_i_u = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,									 ResultSet.CONCUR_UPDATABLE);		// We should have gotten 1 warning 		// and a read only scroll insensitive cursor		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();		}		conn.clearWarnings();		s_i_u.close();		ps_i_r = conn.prepareStatement(									 "select * from t",									 ResultSet.TYPE_SCROLL_INSENSITIVE,									 ResultSet.CONCUR_READ_ONLY);		// We should not have gotten any warnings 		// and should have gotten a prepared scroll insensitive cursor		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("unexpected warning = " + warning);			warning = warning.getNextWarning();			passed = false;		}		conn.clearWarnings();		rs = ps_i_r.executeQuery();		// make sure it's scrollable		rs.last();		rs.close();		ps_i_r.close();		ps_i_u = conn.prepareStatement(									 "select * from t",									 ResultSet.TYPE_SCROLL_INSENSITIVE,									 ResultSet.CONCUR_UPDATABLE);		// We should have gotten 1 warning 		// and a read only scroll insensitive cursor		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();		}		conn.clearWarnings();		ps_i_u.close();		// Check setMaxRows()/getMaxRows()		if (s_i_r.getMaxRows() != 0)		{			System.out.println("getMaxRows() expected to return 0");			passed = false;		}		s_i_r.setMaxRows(5);		if (s_i_r.getMaxRows() != 5)		{			System.out.println("getMaxRows() expected to return 5");			passed = false;		}		rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");		if (rs == null)		{			System.out.println("rs expected to be non-null.");			passed = false;		}		// Iterate straight thru RS, expect only 5 rows.		for (int index = 1; index < 6; index++)		{			if (! rs.next())			{				System.out.println("rs.next() failed, index = " + index);				passed = false;				break;			}		}		// We should not see another row (only 5, not 6)		if (rs.next())		{			System.out.println("rs.next() failed, should not have seen 6th row.");			passed = false;		}		rs.close();		// Jump around and verify setMaxRows() works.		rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");		if (rs == null)		{			System.out.println("rs expected to be non-null.");			passed = false;		}		if (!rs.last())		{			System.out.println("rs.last() failed.");			passed = false;		}		// Iterate backwards thru RS, expect only 4 more (5 total) rows.		for (int index = 1; index < 5; index++)		{			if (! rs.previous())			{				System.out.println("rs.previous() failed, index = " + index);				passed = false;				break;			}		}		// We should not see another row (only 5, not 6)		if (rs.previous())		{			System.out.println("rs.previous() failed, should not have seen 6th row.");			passed = false;		}		rs.close();		rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");		if (rs == null)		{			System.out.println("rs expected to be non-null.");			passed = false;		}		rs.afterLast();		// Iterate backwards thru RS, expect only 5 rows.		for (int index = 1; index < 6; index++)		{			if (! rs.previous())			{				System.out.println("rs.previous() failed, index = " + index);				passed = false;				break;			}		}		// We should not see another row (only 5, not 6)		if (rs.previous())		{			System.out.println("rs.previous() failed, should not have seen 6th row.");			passed = false;		}		rs.close();		// Verify setting maxRows back to 0 works.		s_i_r.setMaxRows(0);		rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");		if (rs == null)		{			System.out.println("rs expected to be non-null.");			passed = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -