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

📄 scrollcursors2.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		}		// Iterate straight thru RS, expect 6 rows.		for (int index = 1; index < 7; index++)		{			if (! rs.next())			{				System.out.println("rs.next() failed, index = " + index);				passed = false;				break;			}		}		// We should not see another row 		if (rs.next())		{			System.out.println("rs.next() failed, should not have seen another row.");			passed = false;		}		rs.close();		return passed;	}	/** 	 * Negative 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 scrollInsensitiveNegative( Connection conn)		throws SQLException 	{		boolean 	passed = true;		ResultSet	rs;		SQLWarning	warning;		Statement	s_i_r = null; // insensitive, read only		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();		// Verify that setMaxRows(-1) fails		try		{			s_i_r.setMaxRows(-1);			// Should never get here			System.out.println("setMaxRows(-1) expected to fail");			passed = false;		}		catch (SQLException sqle)		{			/* Check to be sure the exception is the one we expect */			passed = passed && checkException(sqle, "XJ063");		}		// Verify maxRows still 0		if (s_i_r.getMaxRows() != 0)		{			System.out.println("getMaxRows() expected to return 0");			passed = false;		}		// Empty result set		rs = s_i_r.executeQuery("select * from t where 1=0");		// isBeforeFirst() and isAfterLast() should always return false		// when result set is empty		if (rs.isBeforeFirst())		{			System.out.println("isBeforeFirst() expected to return false on empty result set");			passed = false;		}		if (rs.next())		{			System.out.println("rs.next() expected to show result set is empty");			passed = false;		}		if (rs.previous())		{			System.out.println("rs.previous() expected to show result set is empty");			passed = false;		}		if (rs.isAfterLast())		{			System.out.println("isAfterLast() expected to return false on empty result set");			passed = false;		}		if (rs.isFirst())		{			System.out.println("isFirst() expected to return false on empty result set");			passed = false;		}		if (rs.isLast())		{			System.out.println("isLast() expected to return false on empty result set");			passed = false;		}		if (rs.relative(0))		{			System.out.println("relative(0) expected to return false on empty result set");			passed = false;		}		if (rs.relative(1))		{			System.out.println("relative(1) expected to return false on empty result set");			passed = false;		}		if (rs.relative(-1))		{			System.out.println("relative(-1) expected to return false on empty result set");			passed = false;		}		if (rs.absolute(0))		{			System.out.println("absolute(0) expected to return false on empty result set");			passed = false;		}		if (rs.absolute(1))		{			System.out.println("absolute(1) expected to return false on empty result set");			passed = false;		}		if (rs.absolute(-1))		{			System.out.println("absolute(-1) expected to return false on empty result set");			passed = false;		}		rs.close();		// End of empty result set tests		// Non-empty result set		rs = s_i_r.executeQuery("select * from t");		// Negative fetch size		try		{			rs.setFetchSize(-5);			System.out.println("setFetchSize(-5) expected to fail");			passed = false;		}		catch (SQLException sqle)		{			/* Check to be sure the exception is the one we expect */			passed = passed && checkException(sqle, "XJ062");		}		s_i_r.close();		return passed;	}	/**	 * CallableStatement tests.	 *	 * @param conn	The Connection	 *	 * @return	true if it succeeds, false if it doesn't	 *	 * @exception SQLException	Thrown if some unexpected error happens	 */	public static boolean testCallableStatements( Connection conn)		throws SQLException 	{		boolean		passed = true;		int			warningCount = 0;		SQLWarning	warning;		CallableStatement	cs_s_r = null; // sensitive, read only		CallableStatement	cs_s_u = null; // sensitive, updatable		CallableStatement	cs_i_r = null; // insensitive, read only		CallableStatement	cs_i_u = null; // insensitive, updatable		CallableStatement	cs_f_r = null; // forward only, read only		cs_s_r = conn.prepareCall(								"values cast (? as Integer)",								ResultSet.TYPE_SCROLL_SENSITIVE,								ResultSet.CONCUR_READ_ONLY);		// We should have gotten 1 warnings		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();			warningCount++;		}		if (warningCount != 1)		{			System.out.println("warningCount expected to be 1, not " + warningCount);			passed = false;		}		conn.clearWarnings();		cs_s_r.close();			cs_s_u = conn.prepareCall(								"values cast (? as Integer)",								ResultSet.TYPE_SCROLL_SENSITIVE,								ResultSet.CONCUR_UPDATABLE);		// We should have gotten 2 warnings		warningCount = 0;		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();			warningCount++;		}		if (warningCount != 2)		{			System.out.println("warningCount expected to be 2, not " + warningCount);			passed = false;		}		conn.clearWarnings();		cs_s_u.close();			cs_i_r = conn.prepareCall(								"values cast (? as Integer)",								ResultSet.TYPE_SCROLL_INSENSITIVE,								ResultSet.CONCUR_READ_ONLY);		// We should have gotten 0 warnings		warningCount = 0;		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();			warningCount++;		}		if (warningCount != 0)		{			System.out.println("warningCount expected to be 0, not " + warningCount);			passed = false;		}		conn.clearWarnings();		cs_i_r.close();			cs_i_u = conn.prepareCall(								"values cast (? as Integer)",								ResultSet.TYPE_SCROLL_INSENSITIVE,								ResultSet.CONCUR_UPDATABLE);		// We should have gotten 1 warnings		warningCount = 0;		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();			warningCount++;		}		if (warningCount != 1)		{			System.out.println("warningCount expected to be 1, not " + warningCount);			passed = false;		}		conn.clearWarnings();		cs_i_u.close();			cs_f_r = conn.prepareCall(								"values cast (? as Integer)",								ResultSet.TYPE_FORWARD_ONLY,								ResultSet.CONCUR_READ_ONLY);		// We should have gotten 0 warnings		warningCount = 0;		warning = conn.getWarnings();		while (warning != null)		{			System.out.println("warning = " + warning);			warning = warning.getNextWarning();			warningCount++;		}		if (warningCount != 0)		{			System.out.println("warningCount expected to be 0, not " + warningCount);			passed = false;		}		conn.clearWarnings();		cs_f_r.close();			return passed;	}	/** 	 * Tests for PreparedStatement.getMetaData().	 *	 * @param conn	The connection to use.	 *	 * @return	Whether or not we were successful.	 *	 * @exception SQLException	Thrown if some unexpected error happens	 */	static boolean getMetaDataTests( Connection conn)		throws SQLException 	{		boolean 	passed = true;		PreparedStatement	ps_f_r = null; // forward only, read only		ResultSet	rs;		ResultSetMetaData rsmd_ps;		ResultSetMetaData rsmd_rs;		SQLWarning	warning;		ps_f_r = conn.prepareStatement(									 "select c50, i, 43 from t",									 ResultSet.TYPE_FORWARD_ONLY,									 ResultSet.CONCUR_READ_ONLY);		rsmd_ps = ps_f_r.getMetaData();		if (rsmd_ps == null)		{			System.out.println("rsmd_ps expected to be non-null");			return false;		}		// Now get meta data from result set		rs = ps_f_r.executeQuery();		rsmd_rs = rs.getMetaData();		if (rsmd_rs == null)		{			System.out.println("rsmd_rs expected to be non-null");			return false;		}		// check column count		if (rsmd_ps.getColumnCount() != rsmd_rs.getColumnCount())		{			System.out.println("column count expected to be same, not " +							   rsmd_ps.getColumnCount() +							   " and " +							   rsmd_rs.getColumnCount());			passed = false;		}		// get column name for 2nd column		if (! rsmd_ps.getColumnName(2).equals(rsmd_rs.getColumnName(2)))		{			System.out.println("column name expected to be same, not " +							   rsmd_ps.getColumnName(2) +							   " and " +							   rsmd_rs.getColumnName(2));			passed = false;		}		if (rsmd_ps.isReadOnly(2) != rsmd_rs.isReadOnly(2))		{			System.out.println("isReadOnly() expected to be same, not " +							   rsmd_ps.isReadOnly(2) +							   " and " +							   rsmd_rs.isReadOnly(2));			passed = false;		}				rs.close();		ps_f_r.close();		return passed;	}	/**	 * Check to make sure that the given SQLException is an exception	 * with the expected sqlstate.	 *	 * @param e		The SQLException to check	 * @param SQLState	The sqlstate to look for	 *	 * @return	true means the exception is the expected one	 */	private static boolean checkException(SQLException e,											String SQLState)	{		String				state;		String				nextState;		SQLException		next;		boolean				passed = true;		state = e.getSQLState();		if (! SQLState.equals(state)) {				System.out.println("FAIL -- unexpected exception " + e +					"sqlstate: " + state + SQLState);				passed = false;			}		return passed;	}	/**	 * Clean up after ourselves when testing is done.	 *	 * @param conn	The Connection	 * @param s		A Statement on the Connection	 *	 * @return	true if it succeeds, false if it doesn't	 *	 * @exception SQLException	Thrown if some unexpected error happens	 */	static boolean cleanUp(Connection conn, Statement s) {		try {			/* Drop the table we created */			if (s != null)			{				s.execute("drop table t");			}			/* Close the connection */			if (conn != null)			{				conn.commit();				conn.close();			}		} catch (Throwable e) {			System.out.println("FAIL -- unexpected exception caught in cleanup()");			JDBCDisplayUtil.ShowException(System.out, e);			return false;		}		return true;	}}

⌨️ 快捷键说明

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