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

📄 resultset.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.resultset   Copyright 1999, 2005 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License. */package org.apache.derbyTesting.functionTests.tests.jdbcapi;import java.sql.Connection;import java.sql.Date;import java.sql.DriverManager;import java.sql.ResultSetMetaData;import java.sql.ResultSet;import java.sql.PreparedStatement;import java.sql.Statement;import java.sql.SQLException;import java.sql.Time;import java.sql.Timestamp;import java.sql.Types;import java.lang.reflect.*;import org.apache.derby.tools.ij;import org.apache.derbyTesting.functionTests.util.TestUtil;import org.apache.derbyTesting.functionTests.util.JDBCTestDisplayUtil;import org.apache.derby.iapi.reference.JDBC30Translation;import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;/** * Test of JDBC result set and result set meta-data. * This program simply calls each of the result set and result set meta-data * methods, one by one, and prints the results.  The test passes if the printed * results match a previously stored "master".  Thus this test cannot actually * discern whether it passes or not. * * Test is only touching on known result set hot-spots at present. * * @author ames */public class resultset {  private static Class[] CONN_PARAM = { Integer.TYPE };  private static Object[] CONN_ARG = { new Integer(JDBC30Translation.CLOSE_CURSORS_AT_COMMIT)};	static private boolean isDerbyNet = false;	private static String VALID_DATE_STRING = "'2000-01-01'";	private static String VALID_TIME_STRING = "'15:30:20'";	private static String VALID_TIMESTAMP_STRING = "'2000-01-01 15:30:20'";	private static String NULL_VALUE="NULL";	private static String[] SQLTypes =	{		"SMALLINT",		"INTEGER",		"BIGINT",		"DECIMAL(10,5)",		"REAL",		"DOUBLE",		"CHAR(60)",		"VARCHAR(60)",		"LONG VARCHAR",		"CHAR(60) FOR BIT DATA",		"VARCHAR(60) FOR BIT DATA",		"LONG VARCHAR FOR BIT DATA",		"CLOB(1k)",		"DATE",		"TIME",		"TIMESTAMP",		"BLOB(1k)",	};	private static String[] ColumnNames =	{		"SMALLINTCOL",		"INTEGERCOL",		"BIGINTCOL",		"DECIMALCOL",		"REALCOL",		"DOUBLECOL",		"CHARCOL",		"VARCHARCOL",		"LONGVARCHARCOL",		"CHARFORBITCOL",		"VARCHARFORBITCOL",		"LVARCHARFORBITCOL",		"CLOBCOL",		"DATECOL",		"TIMECOL",		"TIMESTAMPCOL",		"BLOBCOL",	}; private static String[][]SQLData =	{		{NULL_VALUE, "0","1","2"},       // SMALLINT		{NULL_VALUE,"0","1","21"},       // INTEGER		{NULL_VALUE,"0","1","22"},       // BIGINT		{NULL_VALUE,"0.0","1.0","23.0"},      // DECIMAL(10,5)		{NULL_VALUE,"0.0","1.0","24.0"},      // REAL,		{NULL_VALUE,"0.0","1.0","25.0"},      // DOUBLE		{NULL_VALUE,"'0'","'aa'","'2.0'"},      // CHAR(60)		{NULL_VALUE,"'0'","'aa'",VALID_TIME_STRING},      //VARCHAR(60)",		{NULL_VALUE,"'0'","'aa'",VALID_TIMESTAMP_STRING},      // LONG VARCHAR		{NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaaa'"},  // CHAR(60)  FOR BIT DATA		{NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaba'"},  // VARCHAR(60) FOR BIT DATA		{NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaca'"},  //LONG VARCHAR FOR BIT DATA		{NULL_VALUE,"'13'","'14'",NULL_VALUE},     //CLOB(1k)		{NULL_VALUE,VALID_DATE_STRING,VALID_DATE_STRING,NULL_VALUE},        // DATE		{NULL_VALUE,VALID_TIME_STRING,VALID_TIME_STRING,VALID_TIME_STRING},        // TIME		{NULL_VALUE,VALID_TIMESTAMP_STRING,VALID_TIMESTAMP_STRING,VALID_TIMESTAMP_STRING},   // TIMESTAMP		{NULL_VALUE,NULL_VALUE,NULL_VALUE,NULL_VALUE}                 // BLOB	};	public static void main(String[] args) throws Throwable {		isDerbyNet = TestUtil.isNetFramework();		Connection con;		ResultSetMetaData met;		ResultSet rs;		Statement stmt;		String[]  columnNames = {"i", "s", "r", "d", "dt", "t", "ts", "c", "v",							 "dc", "bi", "cbd", "vbd", "lvbd", "cl", "bl"};		System.out.println("Test resultset starting");		try		{			// use the ij utility to read the property file and			// make the initial connection.			ij.getPropertyArg(args);			con = ij.startJBMS();			// Test setCatalog/getCatalog for beetle 5504			con.setCatalog("mycatalog");			String cat = con.getCatalog();			if (cat != null )				System.out.println("ERROR: getCatalog did not return null");			//Use reflection to set the holdability to false so that the test can run in jdk14 and lower jdks as well			try {				Method sh = con.getClass().getMethod("setHoldability", CONN_PARAM);				sh.invoke(con, CONN_ARG);			} catch (Exception e) {System.out.println("shouldn't get that error " + e.getMessage());}//for jdks prior to jdk14			stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,									   ResultSet.CONCUR_UPDATABLE);			stmt.execute("create table t (i int, s smallint, r real, "+				"d double precision, dt date, t time, ts timestamp, "+				"c char(10), v varchar(40) not null, dc dec(10,2),"+				"bi bigint, cbd char(10) for bit data," +				"vbd varchar(10) for bit data,lvbd long varchar for bit data,"+				"cl clob(2G), bl blob(1G) )");			stmt.execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"+						 "time('12:06:06'),timestamp('1990-07-07 07:07:07.000007'),"+						 "'eight','nine', 10.1, 11," + 						 TestUtil.stringToHexLiteral("twelv") +  "," +						 TestUtil.stringToHexLiteral("3teen") +  "," +						 TestUtil.stringToHexLiteral("4teen") +  ", null, null)" );			rs = stmt.executeQuery("select i, s, r, d, dt, t, ts, c, v, dc, bi, cbd, vbd, lvbd, cl, bl from t");			met = rs.getMetaData();			int colCount;			System.out.println("getColumnCount(): "+(colCount=met.getColumnCount()));			// JDBC columns use 1-based counting			for (int i=1;i<=colCount;i++) {				System.out.println("isAutoIncrement("+i+"): "+met.isAutoIncrement(i));				System.out.println("isCaseSensitive("+i+"): "+met.isCaseSensitive(i));				System.out.println("isSearchable("+i+"): "+met.isSearchable(i));				System.out.println("isCurrency("+i+"): "+met.isCurrency(i));				System.out.println("isNullable("+i+"): "+met.isNullable(i));				System.out.println("isSigned("+i+"): "+met.isSigned(i));				System.out.println("getColumnDisplaySize("+i+"): "+met.getColumnDisplaySize(i));				System.out.println("getColumnLabel("+i+"): "+met.getColumnLabel(i));				System.out.println("getColumnName("+i+"): "+met.getColumnName(i));				// beetle 5323				System.out.println("getTableName("+i+"): "+met.getTableName(i));				System.out.println("getSchemaName("+i+"): "+met.getSchemaName(i));				System.out.println("getCatalogName("+i+"): "+met.getCatalogName(i));				System.out.println("getColumnType("+i+"): "+met.getColumnType(i));				System.out.println("getPrecision("+i+"): "+met.getPrecision(i));				System.out.println("getScale("+i+"): "+met.getScale(i));				System.out.println("getColumnTypeName("+i+"): "+met.getColumnTypeName(i));				System.out.println("isReadOnly("+i+"): "+met.isReadOnly(i));				boolean writable = met.isWritable(i);				// JCC Supports updatable resultsets so isWritable is true				if ((isDerbyNet && writable == true) ||					(!isDerbyNet && writable == false))					System.out.println("isWritable("+i+"): Expected isWritable value");				System.out.println("isDefinitelyWritable("+i+"): "+met.isDefinitelyWritable(i));			}			/* Try the various get methods on each column */			while (rs.next())			{				// JDBC columns use 1-based counting				for (int i=1;i<=colCount;i++) {					try {						System.out.println("getBigDecimal("+i+",1): "+											BigDecimalHandler.getBigDecimalString(rs,i));					}					catch (Throwable e) {						System.out.println(							"getBigDecimal("+i+",1) got exception ");						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						if (isDerbyNet)							System.out.println("beetle 5328 - JCC returns incorrect scale for getBigDecimal(String,int)");						System.out.println("getBigDecimal("+										columnNames[i-1]+ ",1): "+										BigDecimalHandler.getBigDecimalString(rs,columnNames[i-1],i));					}					catch (Throwable e) {						System.out.println(							"getBigDecimal("+							columnNames[i-1]+",1) got exception ");						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getBoolean("+i+"): "+													rs.getBoolean(i));					}					catch (Throwable e) {						System.out.println(							"getBoolean("+i+") got exception ");						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getBoolean("+										columnNames[i-1]+ "): "+										rs.getBoolean(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getBoolean("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getByte("+i+"): "+													rs.getByte(i));					}					catch (Throwable e) {						System.out.println(							"getByte("+i+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);	 				}					try {						System.out.println("getByte("+										columnNames[i-1]+ "): "+										rs.getByte(columnNames[i-1]));					}					catch (Throwable e) {						System.out.println(							"getByte("+							columnNames[i-1]+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getBytes("+i+"): "+													showBytes(rs.getBytes(i)));					}					catch (SQLException e) {						System.out.println(							"getBytes("+i+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getBytes("+										columnNames[i-1]+ "): "+										showBytes(rs.getBytes(columnNames[i-1])));					}					catch (SQLException e) {						System.out.println(							"getBytes("+							columnNames[i-1]+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getDate("+i+"): "+													rs.getDate(i));					}					catch (SQLException e) {						System.out.println(							"getDate("+i+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getDate("+										columnNames[i-1]+ "): "+										rs.getDate(columnNames[i-1]));					}					catch (SQLException e) {						System.out.println(							"getDate("+							columnNames[i-1]+") got exception " );						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {						System.out.println("getDouble("+i+"): "+													rs.getDouble(i));					}					catch (Throwable e) {						System.out.println(							"getDouble("+i+") got exception " );						if (e instanceof SQLException)						JDBCTestDisplayUtil.ShowCommonSQLException(System.out, (SQLException)e);					}					try {

⌨️ 快捷键说明

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