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

📄 resultset.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
						System.out.println("getDouble("+										columnNames[i-1]+ "): "+										rs.getDouble(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getDouble("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getFloat("+i+"): "+													rs.getFloat(i));					}					catch (Throwable e) {						System.out.println(							"getFloat("+i+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getFloat("+										columnNames[i-1]+ "): "+										rs.getFloat(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getFloat("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getInt("+i+"): "+													rs.getInt(i));					}					catch (Throwable e) {						System.out.println(							"getInt("+i+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getInt("+										columnNames[i-1]+ "): "+										rs.getInt(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getInt("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getLong("+i+"): "+													rs.getLong(i));					}					catch (Throwable e) {						System.out.println(							"getLong("+i+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getLong("+										columnNames[i-1]+ "): "+										rs.getLong(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getLong("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						// with the bit datatypes the string output is not the same for every run,						// so we need to mask that to prevent false test failures						// this does not test the values returned, just whether it gives an exception.						if (i>11)						{							BigDecimalHandler.getObjectString(rs,i);							System.out.println("getObject("+i+") is ok");						}						else							System.out.println("getObject("+i+"): "+												BigDecimalHandler.getObjectString(rs,i));					}					catch (SQLException e) {						System.out.println(							"getObject("+i+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						// with the bit datatypes the string output is not the same for every run,						// so we need to mask that to prevent false test failures						// this does not test the values returned, just whether it gives an exception.						if (i>11)						{							BigDecimalHandler.getObjectString(rs,columnNames[i-1],i);							System.out.println("getObject("+columnNames[i-1]+") is ok ");						}						else							System.out.println("getObject("+										columnNames[i-1]+ "): "+										BigDecimalHandler.getObjectString(rs,columnNames[i-1],i));					}					catch (SQLException e) {						System.out.println(							"getObject("+							columnNames[i-1]+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getShort("+i+"): "+													rs.getShort(i));					}					catch (Throwable e) {						System.out.println(							"getShort("+i+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getShort("+										columnNames[i-1]+ "): "+										rs.getShort(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getShort("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getString("+i+"): "+													rs.getString(i));					}					catch (SQLException e) {						System.out.println(							"getString("+i+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}										try {						System.out.println("getString("+										columnNames[i-1]+ "): "+										rs.getString(columnNames[i-1]));					}					catch (SQLException e) {						System.out.println(							"getString("+							columnNames[i-1]+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getTime("+i+"): "+													rs.getTime(i));					}					catch (SQLException e) {						System.out.println(							"getTime("+i+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getTime("+										columnNames[i-1]+ "): "+										rs.getTime(columnNames[i-1]));					}					catch (SQLException e) {						System.out.println(							"getTime("+							columnNames[i-1]+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getTimestamp("+i+"): "+													rs.getTimestamp(i));					}					catch (SQLException e) {						System.out.println(							"getTimestamp("+i+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getTimestamp("+										columnNames[i-1]+ "): "+										rs.getTimestamp(columnNames[i-1]));					}					catch (SQLException e) {						System.out.println(							"getTimestamp("+							columnNames[i-1]+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}				}			}			rs.close();			// Try getting a row from the closed result set			try {				rs.next();				System.out.println(					"FAIL - rs.next() allowed on closed result set.");			}			catch (SQLException e) {				System.out.println(					"rs.next() on closed result set got exception " );				JDBCTestDisplayUtil.ShowCommonSQLException(System.out, e);			}			catch (Throwable e) {				System.out.println("rs.next() didn't fail with SQLException as "+					"expected on closed result set.  Got Throwable instead: "+e);			}			// Ensure commit or rollback in auto commit actually does something			stmt.executeUpdate("create table bug4810(i int, b int)");			stmt.executeUpdate("insert into bug4810 values (1,1), (1,2), (1,3), (1,4)");			stmt.executeUpdate("insert into bug4810 values (1,1), (1,2), (1,3), (1,4)");			con.commit();			con.setAutoCommit(true);			con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);			System.out.println("just auto commit");			showLocksForAutoCommitSelect(con, stmt, 0);			System.out.println("commit with auto commit");			showLocksForAutoCommitSelect(con, stmt, 1);			System.out.println("rollback with auto commit");			showLocksForAutoCommitSelect(con, stmt, 2);			stmt.close();			testMutableValues(con);			testCorrelationNamesAndMetaDataCalls(con);			testNullIfAndMetaDataCalls(con);			con.close();		}		catch (SQLException e) {			System.out.println("FAIL -- unexpected exception: " + e.toString());			dumpSQLExceptions(e);			e.printStackTrace();		}		catch (Throwable e) {			System.out.println("FAIL -- unexpected exception: "+e);			e.printStackTrace();		}		System.out.println("Test resultset finished");    }	//test NULLIF(L,R) with and without parameter and check the return value's data type	static private void testNullIfAndMetaDataCalls(Connection conn) throws Throwable	{		System.out.println("Tests to check metadata information of nullif column");		tablesForTestingAllDatatypesCombinations(conn);		testAllDatatypesCombinations(conn);		testParameterForFirstOperandToNullIf(conn);	}          	public static void testParameterForFirstOperandToNullIf( Connection conn) throws Throwable	{		System.out.println("Start testing first operand as parameter to nullif");		PreparedStatement ps;		for (int secondColumnType = 0; secondColumnType < SQLTypes.length; secondColumnType++) {			System.out.println("Testing nullif(?,"+SQLTypes[secondColumnType]+")");			String nullIfString =				new String("SELECT NULLIF(?," + ColumnNames[secondColumnType] +") from AllDataTypesTable");			try {					ps = conn.prepareStatement(nullIfString);					switch(secondColumnType) {						case 0:						case 1:						case 2:						case 3:						case 4:						case 5:						case 6:						case 7:							System.out.println("Testing nullif(?,"+SQLTypes[secondColumnType]+") with setBoolean");							ps.setBoolean(1, true);							break;						case 8: //'LONG VARCHAR'						case 11: //'LONG VARCHAR FOR BIT DATA'						case 12: //'CLOB'						case 16: //'BLOB'						//Take specific case of LONG VARCHAR. Prepare of nullif(?,long varchar)						//fails early on because at bind time, Derby tries to set ? to						//long varchar. But comparison between 2 long varchars is not						//supported and hence bind code in BinaryComparisonOperatorNode fails						//Similar thing happens for CLOB, BLOB and LONG VARCHAR FOR BIT DATA						case 9:						case 10:							System.out.println("Testing nullif(?,"+SQLTypes[secondColumnType]+") with setBinaryStream");							ps.setBinaryStream(1, (java.io.InputStream)null, 1);							break;						case 13://DATE							System.out.println("Testing nullif(?,"+SQLTypes[secondColumnType]+") with setDate");							ps.setDate(1, Date.valueOf("2000-01-01"));							break;						case 14://TIME							System.out.println("Testing nullif(?,"+SQLTypes[secondColumnType]+") with setTime");							ps.setTime(1, Time.valueOf("15:30:20"));							break;						case 15://TIMESTAMP							System.out.println("Testing nullif(?,"+SQLTypes[secondColumnType]+") with setTimestamp");							ps.setTimestamp(1, Timestamp.valueOf("2000-01-01 15:30:20"));							break;						default: break;					}					dumpRS(ps.executeQuery());			} catch (SQLException e)			{				dumpSQLExceptions(e);			}		}	}	public static void testAllDatatypesCombinations( Connection conn) throws Throwable	{		System.out.println("Start testing all datatypes combinations in NULLIF function");		Statement s = conn.createStatement();		for (int firstColumnType = 0; firstColumnType < SQLTypes.length; firstColumnType++) {			StringBuffer nullIfString = new StringBuffer("SELECT NULLIF(" + ColumnNames[firstColumnType]);			for (int secondColumnType = 0; secondColumnType < SQLTypes.length; secondColumnType++) {				try {					StringBuffer completeNullIfString = new StringBuffer(nullIfString.toString() + "," + ColumnNames[secondColumnType]);					System.out.println(completeNullIfString + ") from AllDataTypesTable");

⌨️ 快捷键说明

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