SqlDialect get(DataSource dataSource) { Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); String productName = metaData.getDatabaseProductName(); String productVersion = metaData.getDatabaseProductVersion(); List key = Arrays.asList(productName, productVersion); SqlDialect dialect = map.get(key); if (dialect == null) { final SqlDialect.DatabaseProduct product = SqlDialect.getProduct(productName, productVersion); dialect = new SqlDialect(product, productName, metaData.getIdentifierQuoteString()); map.put(key, dialect); } connection.close(); connection = null; return dialect; } catch (SQLException e) { throw new RuntimeException(e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { // ignore } } } }
public synchronized void serialEvent(SerialPortEvent oEvent) { try { switch (oEvent.getEventType()) { case SerialPortEvent.DATA_AVAILABLE: if (input == null) { System.out.println("here11"); input = new BufferedReader(new InputStreamReader(serialPort.getInputStream())); } String inputLine = input.readLine(); // System.out.println(input.readLine().trim()); if (inputLine.equals("")) { } else { String url = "jdbc:mysql://localhost/secureplanet"; Properties prop = new Properties(); prop.setProperty("user", "root"); prop.setProperty("password", "toor"); Driver d = new com.mysql.jdbc.Driver(); Connection conn = d.connect(url, prop); if (conn == null) { System.out.println("connection failed"); return; } DatabaseMetaData dm = conn.getMetaData(); String dbversion = dm.getDatabaseProductVersion(); String dbname = dm.getDatabaseProductName(); System.out.println("name:" + dbname); System.out.println("version:" + dbversion); String rfidtoken = inputLine.trim(); Statement stmt = conn.createStatement(); Double lat = 17.4416; Double lng = 78.3826; String sql = "INSERT INTO smarttracking " + "VALUES ('" + rfidtoken + "','" + lat + "','" + lng + "')"; stmt.executeUpdate(sql); } break; default: break; } } catch (Exception e) { e.printStackTrace(); } }
private void loadDatabaseMetadata() { if (!databaseMetadataLoaded) { String componentName = "UNKNOWN"; Connection con = null; try { componentName = getMetaComponent().getName(); con = DataSourceConnectionProvider.getByComponent(componentName).getConnection(); DatabaseMetaData metaData = con.getMetaData(); supportsSchemasInDataManipulation = metaData.supportsSchemasInDataManipulation(); Collection timeDateFunctions = Strings.toCollection(metaData.getTimeDateFunctions().toUpperCase()); // // another solution instead of the use of 'if' would be to use a xml with // the information of the functions from each BBDD if ("DB2 UDB for AS/400".equals(metaData.getDatabaseProductName()) || "Oracle".equals(metaData.getDatabaseProductName()) || "PostgresSQL".equals(metaData.getDatabaseProductName())) { supportsTranslateFunction = true; } if ("Oracle".equals(metaData.getDatabaseProductName()) || "PostgreSQL".equals(metaData.getDatabaseProductName())) { supportsYearFunction = supportsMonthFunction = false; } else { supportsYearFunction = timeDateFunctions.contains("YEAR"); supportsMonthFunction = timeDateFunctions.contains("MONTH"); } databaseMetadataLoaded = true; } catch (Exception ex) { log.warn(XavaResources.getString("load_database_metadata_warning")); } finally { try { if (con != null) { con.close(); } } catch (SQLException e) { log.warn(XavaResources.getString("close_connection_warning")); } } } }
@Signature public Memory getMetaData() throws SQLException { ArrayMemory r = new ArrayMemory(); r.refOfIndex("userName").assign(metaData.getUserName()); r.refOfIndex("driverName").assign(metaData.getDriverName()); r.refOfIndex("driverVersion").assign(metaData.getDriverVersion()); r.refOfIndex("databaseName").assign(metaData.getDatabaseProductName()); r.refOfIndex("databaseVersion").assign(metaData.getDatabaseProductVersion()); r.refOfIndex("catalogSeparator").assign(metaData.getCatalogSeparator()); r.refOfIndex("catalogTerm").assign(metaData.getCatalogTerm()); r.refOfIndex("schemaTerm").assign(metaData.getSchemaTerm()); r.refOfIndex("procedureTerm").assign(metaData.getProcedureTerm()); r.refOfIndex("searchStringEscape").assign(metaData.getSearchStringEscape()); r.refOfIndex("numericFunctions").assign(metaData.getNumericFunctions()); r.refOfIndex("stringFunctions").assign(metaData.getStringFunctions()); r.refOfIndex("timeDateFunctions").assign(metaData.getTimeDateFunctions()); r.refOfIndex("systemFunctions").assign(metaData.getSystemFunctions()); r.refOfIndex("defaultTransactionIsolation").assign(metaData.getDefaultTransactionIsolation()); r.refOfIndex("identifierQuoteString").assign(metaData.getIdentifierQuoteString()); r.refOfIndex("maxBinaryLiteralLength").assign(metaData.getMaxBinaryLiteralLength()); r.refOfIndex("maxCatalogNameLength").assign(metaData.getMaxCatalogNameLength()); r.refOfIndex("maxCharLiteralLength").assign(metaData.getMaxCharLiteralLength()); r.refOfIndex("maxConnections").assign(metaData.getMaxConnections()); r.refOfIndex("maxColumnNameLength").assign(metaData.getMaxColumnNameLength()); r.refOfIndex("maxColumnsInGroupBy").assign(metaData.getMaxColumnsInGroupBy()); r.refOfIndex("maxColumnsInIndex").assign(metaData.getMaxColumnsInIndex()); r.refOfIndex("maxColumnsInOrderBy").assign(metaData.getMaxColumnsInOrderBy()); r.refOfIndex("maxColumnsInSelect").assign(metaData.getMaxColumnsInSelect()); r.refOfIndex("maxColumnsInTable").assign(metaData.getMaxColumnsInTable()); r.refOfIndex("maxCursorNameLength").assign(metaData.getMaxCursorNameLength()); r.refOfIndex("maxIndexLength").assign(metaData.getMaxIndexLength()); r.refOfIndex("maxProcedureNameLength").assign(metaData.getMaxProcedureNameLength()); r.refOfIndex("maxRowSize").assign(metaData.getMaxRowSize()); r.refOfIndex("maxSchemaNameLength").assign(metaData.getMaxSchemaNameLength()); r.refOfIndex("maxStatementLength").assign(metaData.getMaxStatementLength()); r.refOfIndex("maxTableNameLength").assign(metaData.getMaxTableNameLength()); r.refOfIndex("maxTablesInSelect").assign(metaData.getMaxTablesInSelect()); return r.toConstant(); }
private static Map<PwmAboutProperty, String> getConnectionDebugProperties( final Connection connection) { if (connection != null) { try { final Map<PwmAboutProperty, String> returnObj = new LinkedHashMap<>(); final DatabaseMetaData databaseMetaData = connection.getMetaData(); returnObj.put(PwmAboutProperty.database_driverName, databaseMetaData.getDriverName()); returnObj.put(PwmAboutProperty.database_driverVersion, databaseMetaData.getDriverVersion()); returnObj.put( PwmAboutProperty.database_databaseProductName, databaseMetaData.getDatabaseProductName()); returnObj.put( PwmAboutProperty.database_databaseProductVersion, databaseMetaData.getDatabaseProductVersion()); return Collections.unmodifiableMap(returnObj); } catch (SQLException e) { LOGGER.error("error rading jdbc meta data: " + e.getMessage()); } } return Collections.emptyMap(); }
static void truncateTable(String strTable) { String DBMS = ""; try { DatabaseMetaData metaData = conn.getMetaData(); DBMS = metaData.getDatabaseProductName().toLowerCase(); } catch (SQLException e) { System.out.println("Problem determining database product name: " + e); } System.out.println("Truncating '" + strTable + "' ..."); try { if (DBMS.startsWith("db2")) { stmt.execute("TRUNCATE TABLE " + strTable + " IMMEDIATE"); } else { stmt.execute("TRUNCATE TABLE " + strTable); } transCommit(); } catch (SQLException se) { System.out.println(se.getMessage()); transRollback(); } }
/** * 初始化连接池 * * @param props * @param show_sql */ private static final void initDataSource(Properties dbProperties) { try { if (dbProperties == null) { dbProperties = new Properties(); dbProperties.load(DBManager.class.getResourceAsStream(CONFIG_PATH)); } // Class.forName(dbProperties.getProperty("jdbc.driverClass")); for (Object key : dbProperties.keySet()) { String skey = (String) key; if (skey.startsWith("jdbc.")) { String name = skey.substring(5); cp_props.put(name, dbProperties.getProperty(skey)); if ("show_sql".equalsIgnoreCase(name)) { show_sql = "true".equalsIgnoreCase(dbProperties.getProperty(skey)); } } } dataSource = (DataSource) Class.forName(cp_props.getProperty("datasource")).newInstance(); if (dataSource.getClass().getName().indexOf("c3p0") > 0) { // Disable JMX in C3P0 System.setProperty( "com.mchange.v2.c3p0.management.ManagementCoordinator", "com.mchange.v2.c3p0.management.NullManagementCoordinator"); } log.info("Using DataSource : " + dataSource.getClass().getName()); BeanUtils.populate(dataSource, cp_props); Connection conn = getConnection(); DatabaseMetaData mdm = conn.getMetaData(); log.info( "Connected to " + mdm.getDatabaseProductName() + " " + mdm.getDatabaseProductVersion()); closeConnection(); } catch (Exception e) { e.printStackTrace(); throw new DBException(e); } }
/** Method declaration */ private void refreshTree() { tTree.removeAll(); try { int color_table = Color.yellow.getRGB(); int color_column = Color.orange.getRGB(); int color_index = Color.red.getRGB(); tTree.addRow("", dMeta.getURL(), "-", 0); String usertables[] = {"TABLE"}; ResultSet result = dMeta.getTables(null, null, null, usertables); Vector tables = new Vector(); // sqlbob@users Added remarks. Vector remarks = new Vector(); while (result.next()) { tables.addElement(result.getString(3)); remarks.addElement(result.getString(5)); } result.close(); for (int i = 0; i < tables.size(); i++) { String name = (String) tables.elementAt(i); String key = "tab-" + name + "-"; tTree.addRow(key, name, "+", color_table); // sqlbob@users Added remarks. String remark = (String) remarks.elementAt(i); if ((remark != null) && !remark.trim().equals("")) { tTree.addRow(key + "r", " " + remark); } ResultSet col = dMeta.getColumns(null, null, name, null); while (col.next()) { String c = col.getString(4); String k1 = key + "col-" + c + "-"; tTree.addRow(k1, c, "+", color_column); String type = col.getString(6); tTree.addRow(k1 + "t", "Type: " + type); boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls; tTree.addRow(k1 + "n", "Nullable: " + nullable); } col.close(); tTree.addRow(key + "ind", "Indices", "+", 0); ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false); String oldiname = null; while (ind.next()) { boolean nonunique = ind.getBoolean(4); String iname = ind.getString(6); String k2 = key + "ind-" + iname + "-"; if ((oldiname == null || !oldiname.equals(iname))) { tTree.addRow(k2, iname, "+", color_index); tTree.addRow(k2 + "u", "Unique: " + !nonunique); oldiname = iname; } String c = ind.getString(9); tTree.addRow(k2 + "c-" + c + "-", c); } ind.close(); } tTree.addRow("p", "Properties", "+", 0); tTree.addRow("pu", "User: "******"pr", "ReadOnly: " + cConn.isReadOnly()); tTree.addRow("pa", "AutoCommit: " + cConn.getAutoCommit()); tTree.addRow("pd", "Driver: " + dMeta.getDriverName()); tTree.addRow("pp", "Product: " + dMeta.getDatabaseProductName()); tTree.addRow("pv", "Version: " + dMeta.getDatabaseProductVersion()); } catch (SQLException e) { tTree.addRow("", "Error getting metadata:", "-", 0); tTree.addRow("-", e.getMessage()); tTree.addRow("-", e.getSQLState()); } tTree.update(); }
protected void initColumns(ConnectionProvider cp) { if (cp != null) try { DatabaseMetaData dmd = cp.getDatabaseMetaData(); String shortTableName = getName().getName(); ResultSet rs; // rs = dmd.getColumns(cp.getConnection().getCatalog(), // dmd.getUserName().trim(), shortTableName, "%"); rs = dmd.getColumns(cp.getConnection().getCatalog(), cp.getSchema(), shortTableName, "%"); int sqlType; String sqlTypeName; String colName, colNull, colSize, colDec; if (rs != null) { HashMap rset = new HashMap(); while (rs.next()) { sqlType = rs.getInt("DATA_TYPE"); // NOI18N sqlTypeName = rs.getString("TYPE_NAME").trim(); // NOI18N colName = rs.getString("COLUMN_NAME").trim(); // NOI18N colNull = Integer.toString(rs.getInt("NULLABLE")); // NOI18N colSize = rs.getString("COLUMN_SIZE"); // NOI18N colDec = rs.getString("DECIMAL_DIGITS"); // NOI18N String dbProductName = dmd.getDatabaseProductName().trim(); // Oracle driver hacks if (dbProductName.indexOf("Oracle") != -1) { // NOI18N if (sqlType == 11 || ((sqlType == 1111) && sqlTypeName.startsWith("TIMESTAMP"))) sqlType = Types.TIMESTAMP; if ((sqlType == 1111) && sqlTypeName.equals("FLOAT")) // NOI18N sqlType = Types.DOUBLE; if ((sqlType == 1111) && sqlTypeName.equals("BLOB")) // NOI18N sqlType = Types.BLOB; if ((sqlType == 1111) && sqlTypeName.equals("CLOB")) // NOI18N sqlType = Types.CLOB; if ((sqlType == 1111) && sqlTypeName.equals("NVARCHAR2")) // NOI18N sqlType = Types.CHAR; } // MySQL driver hacks if (dbProductName.indexOf("MySQL") != -1) { // NOI18N if ((sqlType == 1111) && sqlTypeName.equalsIgnoreCase("BIT")) // NOI18N sqlType = Types.BIT; } // workaround for i-net Oranxo driver // value in int range is expected by JDBC API but 4294967296 is returned try { new Integer(colSize); } catch (NumberFormatException exc) { colSize = Integer.toString(Integer.MAX_VALUE); } ColumnElementImpl cei = new ColumnElementImpl(colName, Integer.toString(sqlType), colNull, colSize, colDec); ColumnElement ce = new ColumnElement(cei, (TableElement) element); ColumnElement[] c = {ce}; changeColumns(c, DBElement.Impl.ADD); } rs.close(); } } catch (Exception exc) { if (Boolean.getBoolean("netbeans.debug.exceptions")) // NOI18N exc.printStackTrace(); } }
/* Clear all existing nodes from the tree model and rebuild from scratch. */ protected void refreshTree() { DefaultMutableTreeNode propertiesNode; DefaultMutableTreeNode leaf; // First clear the existing tree by simply enumerating // over the root node's children and removing them one by one. while (treeModel.getChildCount(rootNode) > 0) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeModel.getChild(rootNode, 0); treeModel.removeNodeFromParent(child); child.removeAllChildren(); child.removeFromParent(); } treeModel.nodeStructureChanged(rootNode); treeModel.reload(); tScrollPane.repaint(); // Now rebuild the tree below its root try { // Start by naming the root node from its URL: rootNode.setUserObject(dMeta.getURL()); // get metadata about user tables by building a vector of table names String usertables[] = {"TABLE", "GLOBAL TEMPORARY", "VIEW"}; ResultSet result = dMeta.getTables(null, null, null, usertables); Vector tables = new Vector(); // sqlbob@users Added remarks. Vector remarks = new Vector(); while (result.next()) { tables.addElement(result.getString(3)); remarks.addElement(result.getString(5)); } result.close(); // For each table, build a tree node with interesting info for (int i = 0; i < tables.size(); i++) { String name = (String) tables.elementAt(i); DefaultMutableTreeNode tableNode = makeNode(name, rootNode); ResultSet col = dMeta.getColumns(null, null, name, null); // sqlbob@users Added remarks. String remark = (String) remarks.elementAt(i); if ((remark != null) && !remark.trim().equals("")) { makeNode(remark, tableNode); } // With a child for each column containing pertinent attributes while (col.next()) { String c = col.getString(4); DefaultMutableTreeNode columnNode = makeNode(c, tableNode); String type = col.getString(6); makeNode("Type: " + type, columnNode); boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls; makeNode("Nullable: " + nullable, columnNode); } col.close(); DefaultMutableTreeNode indexesNode = makeNode("Indices", tableNode); ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false); String oldiname = null; // A child node to contain each index - and its attributes while (ind.next()) { DefaultMutableTreeNode indexNode = null; boolean nonunique = ind.getBoolean(4); String iname = ind.getString(6); if ((oldiname == null || !oldiname.equals(iname))) { indexNode = makeNode(iname, indexesNode); makeNode("Unique: " + !nonunique, indexNode); oldiname = iname; } // And the ordered column list for index components makeNode(ind.getString(9), indexNode); } ind.close(); } // Finally - a little additional metadata on this connection propertiesNode = makeNode("Properties", rootNode); makeNode("User: "******"ReadOnly: " + cConn.isReadOnly(), propertiesNode); makeNode("AutoCommit: " + cConn.getAutoCommit(), propertiesNode); makeNode("Driver: " + dMeta.getDriverName(), propertiesNode); makeNode("Product: " + dMeta.getDatabaseProductName(), propertiesNode); makeNode("Version: " + dMeta.getDatabaseProductVersion(), propertiesNode); } catch (SQLException se) { propertiesNode = makeNode("Error getting metadata:", rootNode); makeNode(se.getMessage(), propertiesNode); makeNode(se.getSQLState(), propertiesNode); } treeModel.nodeStructureChanged(rootNode); treeModel.reload(); tScrollPane.repaint(); }
public void testMetaData() { String ddl0 = "DROP TABLE ADDRESSBOOK IF EXISTS; DROP TABLE ADDRESSBOOK_CATEGORY IF EXISTS; DROP TABLE USER IF EXISTS;"; String ddl1 = "CREATE TABLE USER(USER_ID INTEGER NOT NULL PRIMARY KEY,LOGIN_ID VARCHAR(128) NOT NULL,USER_NAME VARCHAR(254) DEFAULT ' ' NOT NULL,CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,UPDATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,LAST_ACCESS_DATE TIMESTAMP,CONSTRAINT IXUQ_LOGIN_ID0 UNIQUE(LOGIN_ID))"; String ddl2 = "CREATE TABLE ADDRESSBOOK_CATEGORY(USER_ID INTEGER NOT NULL,CATEGORY_ID INTEGER DEFAULT 0 NOT NULL,CATEGORY_NAME VARCHAR(60) DEFAULT '' NOT NULL,CONSTRAINT SYS_PK_ADDRESSBOOK_CATEGORY PRIMARY KEY(USER_ID,CATEGORY_ID),CONSTRAINT FK_ADRBKCAT1 FOREIGN KEY(USER_ID) REFERENCES USER(USER_ID) ON DELETE CASCADE)"; String ddl3 = "CREATE TABLE ADDRESSBOOK(USER_ID INTEGER NOT NULL,ADDRESSBOOK_ID INTEGER NOT NULL,CATEGORY_ID INTEGER DEFAULT 0 NOT NULL,FIRST VARCHAR(64) DEFAULT '' NOT NULL,LAST VARCHAR(64) DEFAULT '' NOT NULL,NOTE VARCHAR(128) DEFAULT '' NOT NULL,CONSTRAINT SYS_PK_ADDRESSBOOK PRIMARY KEY(USER_ID,ADDRESSBOOK_ID),CONSTRAINT FK_ADRBOOK1 FOREIGN KEY(USER_ID,CATEGORY_ID) REFERENCES ADDRESSBOOK_CATEGORY(USER_ID,CATEGORY_ID) ON DELETE CASCADE)"; String result1 = "1"; String result2 = "2"; String result3 = "3"; String result4 = "4"; String result5 = "5"; try { stmnt.execute(ddl0); stmnt.execute(ddl1); stmnt.execute(ddl2); stmnt.execute(ddl3); DatabaseMetaData md = connection.getMetaData(); { // System.out.println(md.getDatabaseMajorVersion()); // System.out.println(md.getDatabaseMinorVersion()); System.out.println(md.getDatabaseProductName()); System.out.println(md.getDatabaseProductVersion()); System.out.println(md.getDefaultTransactionIsolation()); System.out.println(md.getDriverMajorVersion()); System.out.println(md.getDriverMinorVersion()); System.out.println(md.getDriverName()); System.out.println(md.getDriverVersion()); System.out.println(md.getExtraNameCharacters()); System.out.println(md.getIdentifierQuoteString()); // System.out.println(md.getJDBCMajorVersion()); // System.out.println(md.getJDBCMinorVersion()); System.out.println(md.getMaxBinaryLiteralLength()); System.out.println(md.getMaxCatalogNameLength()); System.out.println(md.getMaxColumnsInGroupBy()); System.out.println(md.getMaxColumnsInIndex()); System.out.println(md.getMaxColumnsInOrderBy()); System.out.println(md.getMaxColumnsInSelect()); System.out.println(md.getMaxColumnsInTable()); System.out.println(md.getMaxConnections()); System.out.println(md.getMaxCursorNameLength()); System.out.println(md.getMaxIndexLength()); System.out.println(md.getMaxProcedureNameLength()); System.out.println(md.getMaxRowSize()); System.out.println(md.getMaxSchemaNameLength()); System.out.println(md.getMaxStatementLength()); System.out.println(md.getMaxStatements()); System.out.println(md.getMaxTableNameLength()); System.out.println(md.getMaxUserNameLength()); System.out.println(md.getNumericFunctions()); System.out.println(md.getProcedureTerm()); // System.out.println(md.getResultSetHoldability()); System.out.println(md.getSchemaTerm()); System.out.println(md.getSearchStringEscape()); System.out.println(md.getSQLKeywords()); // System.out.println(md.getSQLStateType()); System.out.println(md.getStringFunctions()); System.out.println(md.getSystemFunctions()); System.out.println(md.getTimeDateFunctions()); System.out.println(md.getURL()); System.out.println(md.getUserName()); System.out.println(md.importedKeyCascade); System.out.println(md.isCatalogAtStart()); System.out.println(md.isReadOnly()); ResultSet rs; rs = md.getPrimaryKeys(null, null, "USER"); ResultSetMetaData rsmd = rs.getMetaData(); String result0 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result0 += rs.getString(i + 1) + ":"; } result0 += "\n"; } rs.close(); System.out.println(result0); } { ResultSet rs; rs = md.getBestRowIdentifier(null, null, "USER", 0, true); ResultSetMetaData rsmd = rs.getMetaData(); String result0 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result0 += rs.getString(i + 1) + ":"; } result0 += "\n"; } rs.close(); System.out.println(result0); } { ResultSet rs = md.getImportedKeys(null, null, "ADDRESSBOOK"); ResultSetMetaData rsmd = rs.getMetaData(); result1 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result1 += rs.getString(i + 1) + ":"; } result1 += "\n"; } rs.close(); System.out.println(result1); } { ResultSet rs = md.getCrossReference(null, null, "ADDRESSBOOK_CATEGORY", null, null, "ADDRESSBOOK"); ResultSetMetaData rsmd = rs.getMetaData(); result2 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result2 += rs.getString(i + 1) + ":"; } result2 += "\n"; } rs.close(); System.out.println(result2); } { ResultSet rs = md.getExportedKeys(null, null, "USER"); ResultSetMetaData rsmd = rs.getMetaData(); result3 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result3 += rs.getString(i + 1) + ":"; } result3 += "\n"; } rs.close(); System.out.println(result3); } { ResultSet rs = md.getCrossReference(null, null, "USER", null, null, "ADDRESSBOOK_CATEGORY"); ResultSetMetaData rsmd = rs.getMetaData(); result4 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result4 += rs.getString(i + 1) + ":"; } result4 += "\n"; } rs.close(); System.out.println(result4); } { stmnt.execute("DROP TABLE T IF EXISTS;"); stmnt.executeQuery("CREATE TABLE T (I IDENTITY, A CHAR, B CHAR);"); stmnt.executeQuery( "INSERT INTO T VALUES (NULL, 'get_column_name', '" + getColumnName + "');"); ResultSet rs = stmnt.executeQuery("SELECT I, A, B, A \"aliasA\", B \"aliasB\" FROM T;"); ResultSetMetaData rsmd = rs.getMetaData(); result5 = ""; for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result5 += rsmd.getColumnName(i + 1) + ":" + rs.getString(i + 1) + ":"; } result5 += "\n"; } rs.close(); rs = stmnt.executeQuery("SELECT I, A, B, A \"aliasA\", B \"aliasB\" FROM T;"); ; rsmd = rs.getMetaData(); for (; rs.next(); ) { for (int i = 0; i < rsmd.getColumnCount(); i++) { result5 += rsmd.getColumnLabel(i + 1) + ":" + rs.getString(i + 1) + ":"; } result5 += "\n"; } System.out.println(result5); System.out.println("first column identity: " + rsmd.isAutoIncrement(1)); rsmd.isCaseSensitive(1); rsmd.isCurrency(1); rsmd.isDefinitelyWritable(1); rsmd.isNullable(1); rsmd.isReadOnly(1); rsmd.isSearchable(1); rsmd.isSigned(1); rsmd.isWritable(1); rs.close(); // test identity with PreparedStatement pstmnt = connection.prepareStatement("INSERT INTO T VALUES (?,?,?)"); pstmnt.setString(1, null); pstmnt.setString(2, "test"); pstmnt.setString(3, "test2"); pstmnt.executeUpdate(); pstmnt = connection.prepareStatement("call identity()"); ResultSet rsi = pstmnt.executeQuery(); rsi.next(); int identity = rsi.getInt(1); System.out.println("call identity(): " + identity); rsi.close(); } } catch (SQLException e) { fail(e.getMessage()); } System.out.println("testMetaData complete"); // assert equality of exported and imported with xref assertEquals(result1, result2); assertEquals(result3, result4); }