get synonyms metadata using the JDBC driver
Posted in 2009
Topics: Connectivity: ODBC / JDBC / .NET, Java & JDBC Development
Hi, I want to get the list of synonyms and the list of columns for each one of the synonym using the informix JDBC driver. I tried: connection.getMetaData().getColumns() but synonyms are not returned by this function. I think I'm missing a connection property. Thanks, Ori
DatabaseMetaData.getTables() is the method that will give you the list of tables. One of the fields in the resultSet is the type of the Table - TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". Is this what you are looking for? VG.
Hi, I tried this with a simple Java app connecting to IDS 11.50.TC5 using the Informix JDBC library and got the desired results. "cust" is a synonym for "customer" VG. DatabaseMetaData dbmd= conn.getMetaData(); ResultSet rs = dbmd.getTables(null,"schemaname","%",null); while(rs.next()) { System.out.println("Details for Table : " + rs.getString(3) + " Type: " + rs.getString(4)); if(rs.getString(4).equals("SYNONYM") || rs.getString(4).equals("TABLE")) { //Get columns for each table/synonym ResultSet colrs = dbmd.getColumns(null,"schemaname",rs.getString(3),"%"); while(colrs.next()) { System.out.println(colrs.getString(4)); } colrs.close(); } } rs.close(); Output - Details for Table : cust Type: SYNONYM customer_num fname lname company address1 address2 city state zipcode phone Details for Table : call_type Type: TABLE call_code code_descr Details for Table : catalog Type: TABLE catalog_num stock_num manu_code cat_descr cat_picture cat_advert Details for Table : cust_calls Type: TABLE customer_num call_dtime user_id call_code call_descr res_dtime res_descr Details for Table : custlisttab Type: TABLE customer_num name address zip phone symbol url Details for Table : customer Type: TABLE customer_num fname lname company address1 address2 city state zipcode phone Details for Table : items Type: TABLE item_num order_num stock_num manu_code quantity total_price Details for Table : manufact Type: TABLE manu_code manu_name lead_time Details for Table : orders Type: TABLE order_num order_date customer_num ship_instruct backlog po_num ship_date ship_weight ship_charge paid_date Details for Table : state Type: TABLE code sname Details for Table : stock Type: TABLE stock_num manu_code description unit_price unit unit_descr