c# barcode reader library WEB ACCESS TO METADATA, PART 2 in Font

Generate PDF 417 in Font WEB ACCESS TO METADATA, PART 2

CHAPTER 9 WEB ACCESS TO METADATA, PART 2
Generating PDF417 In None
Using Barcode creator for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
European Article Number 13 Creation In None
Using Barcode encoder for Font Control to generate, create EAN13 image in Font applications.
www.OnBarcode.com
Invoking GetTablePrivileges for MySQL
Making ANSI/AIM Code 39 In None
Using Barcode printer for Font Control to generate, create Code39 image in Font applications.
www.OnBarcode.com
Generate Barcode In None
Using Barcode generator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Figure 9-13 shows how to run the solution for the MySQL database.
Creating PDF417 In None
Using Barcode generator for Font Control to generate, create PDF417 image in Font applications.
www.OnBarcode.com
Create QR Code JIS X 0510 In None
Using Barcode creator for Font Control to generate, create Quick Response Code image in Font applications.
www.OnBarcode.com
Figure 9-13. Invoking GetTablePrivileges for MySQL (XML output)
Print UPCA In None
Using Barcode maker for Font Control to generate, create Universal Product Code version A image in Font applications.
www.OnBarcode.com
Encoding Postnet In None
Using Barcode printer for Font Control to generate, create Postnet image in Font applications.
www.OnBarcode.com
CHAPTER 9 WEB ACCESS TO METADATA, PART 2
PDF-417 2d Barcode Recognizer In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Reading PDF-417 2d Barcode In Visual Basic .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Invoking GetTablePrivileges for Oracle
2D Barcode Generation In Java
Using Barcode drawer for Java Control to generate, create Matrix 2D Barcode image in Java applications.
www.OnBarcode.com
Print Barcode In Java
Using Barcode creator for Eclipse BIRT Control to generate, create Barcode image in Eclipse BIRT applications.
www.OnBarcode.com
Figure 9-14 shows how to run the solution for the Oracle database.
ECC200 Decoder In Visual Basic .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
GS1 - 13 Encoder In Java
Using Barcode generator for Android Control to generate, create EAN-13 Supplement 5 image in Android applications.
www.OnBarcode.com
Figure 9-14. Invoking GetTablePrivileges for Oracle (XML output)
Paint Code128 In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create Code 128B image in ASP.NET applications.
www.OnBarcode.com
Draw Matrix Barcode In Visual Basic .NET
Using Barcode maker for .NET Control to generate, create 2D Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
9.8. What Are the Column Privileges
UPC - 13 Scanner In VS .NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
EAN / UCC - 14 Generation In Visual Studio .NET
Using Barcode drawer for Reporting Service Control to generate, create GS1-128 image in Reporting Service applications.
www.OnBarcode.com
A database column s privileges refers to finding a description of the access rights for columns of a table available in a catalog or schema. DatabaseMetaData provides a method, getColumnPrivileges(), to do just that. This method returns the result as a ResultSet object where each row is a column privilege description. In web-based applications, returning the result as a ResultSet is not useful. It is better to return the result as an HTML/XML object so that the client can extract the required information and display it in a desired format. It would be wrong to assume that this privilege applies to all columns; while this may be true for some systems, it is not true for all. getColumnPrivileges() returns only privileges that match the schema and table name criteria. They are ordered by COLUMN_NAME and PRIVILEGE. Each privilege description has the columns shown in Table 9-6.
DataMatrix Drawer In VB.NET
Using Barcode drawer for .NET framework Control to generate, create Data Matrix 2d barcode image in .NET applications.
www.OnBarcode.com
Barcode Generation In .NET
Using Barcode printer for VS .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
CHAPTER 9 WEB ACCESS TO METADATA, PART 2
Table 9-6. Columns for Result of Invoking getColumnPrivileges()
Column s Position
1 2 3 4 5 6 7 8
Type
TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME GRANTOR GRANTEE PRIVILEGE IS_GRANTABLE
Name
String String String String String String String String
Description
Table catalog (may be null) Table schema (may be null) Table name (as a String) Column name (as a String) Grantor of access (may be null) Grantee of access Name of access (SELECT, INSERT, UPDATE, REFERENCES, etc.) YES if grantee is permitted to grant to others; NO if not; null if unknown
The getColumnPrivileges() method has the following signature: public java.sql.ResultSet getTablePrivileges(String String String String throws java.sql.SQLException where catalog is a catalog name; "" retrieves those without a catalog. schema is a schema name; "" retrieves those without a schema. table is a table name pattern. columnNamePattern is a column name pattern. Next let s look at a Java servlet, GetTablePrivileges, which has the following signature: GetColumnPrivileges vendor=<db-vendor>& catalog=<catalog-name>& schema=<schema-name>& table=<table-name> format=<xml/html> catalog, schema, table, columnNamePattern)
The Solution
import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.PrintWriter; import java.io.IOException;
CHAPTER 9 WEB ACCESS TO METADATA, PART 2
import jcb.util.DatabaseUtil; import jcb.db.VeryBasicConnectionManager; public class GetColumnPrivileges extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ResultSet columnPrivileges = null; Connection conn = null; try { String dbVendor = request.getParameter("vendor").trim(); String outputFormat = request.getParameter("format").trim(); String table = request.getParameter("table").trim(); conn = VeryBasicConnectionManager.getConnection(dbVendor); if (dbVendor.equals("mysql")) { columnPrivileges = getColumnPrivileges(conn, conn.getCatalog(), // catalog, null, // schema table, // table "%"); // all columns } else if (dbVendor.equals("oracle")) { String schema = request.getParameter("schema").trim(); columnPrivileges = getColumnPrivileges(conn, conn.getCatalog(), // catalog, schema, // schema table, // table "%"); // all columns } else { printError(response, "unknown db vendor"); return; } if (outputFormat.equals("xml")) { printXML(response, columnPrivileges); } else { printHTML(response, columnPrivileges); } } catch(Exception e) { e.printStackTrace(); printError(response, e.getMessage()); }
CHAPTER 9 WEB ACCESS TO METADATA, PART 2
finally { DatabaseUtil.close(columnPrivileges); DatabaseUtil.close(conn); } } // end doGet private static void printHTML(HttpServletResponse response, ResultSet columnPrivileges) throws Exception { response.setContentType("text/html"); PrintWriter out = response.getWriter(); StringBuilder buffer = new StringBuilder(); buffer.append("<html><body><table border=1 cellspacing=0 cellpadding=0>"); buffer.append("<TR><TH>Catalog</TH>"); buffer.append("<TH>Schema</TH>"); buffer.append("<TH>Table Name</TH>"); buffer.append("<TH>Column Name</TH>"); buffer.append("<TH>Grantor</TH>"); buffer.append("<TH>Grantee</TH>"); buffer.append("<TH>Privilege</TH>"); buffer.append("<TH>Is Grantable</TH></TR>"); while (columnPrivileges.next()) { buffer.append("<TR><TD>"); buffer.append(columnPrivileges.getString("TABLE_CAT")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("TABLE_SCHEM")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("TABLE_NAME")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("COLUMN_NAME")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("GRANTOR")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("GRANTEE")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("PRIVILEGE")); buffer.append("</TD><TD>"); buffer.append(columnPrivileges.getString("IS_GRANTABLE")); buffer.append("</TD></TR>"); } buffer.append("</table></body></html>"); out.println(buffer.toString()); }
CHAPTER 9 WEB ACCESS TO METADATA, PART 2
private static void printXML(HttpServletResponse response, ResultSet columnPrivileges) throws Exception { response.setContentType("text/xml"); PrintWriter out = response.getWriter(); StringBuilder buffer = new StringBuilder(); buffer.append("< xml version=\"1.0\" >"); buffer.append("<table_privileges>"); while (columnPrivileges.next()) { buffer.append("<table_privilege><catalog>"); buffer.append(columnPrivileges.getString("TABLE_CAT")); buffer.append("</catalog><schema>"); buffer.append(columnPrivileges.getString("TABLE_SCHEM")); buffer.append("</schema><tableName>"); buffer.append(columnPrivileges.getString("TABLE_NAME")); buffer.append("</tableName><columnName>"); buffer.append(columnPrivileges.getString("COLUMN_NAME")); buffer.append("</columnName><grantor>"); buffer.append(columnPrivileges.getString("GRANTOR")); buffer.append("</grantor><grantee>"); buffer.append(columnPrivileges.getString("GRANTEE")); buffer.append("</grantee><privilege>"); buffer.append(columnPrivileges.getString("PRIVILEGE")); buffer.append("</privilege><is_grantable>"); buffer.append(columnPrivileges.getString("IS_GRANTABLE")); buffer.append("</is_grantable></table_privilege>"); } buffer.append("</table_privileges>"); out.println(buffer.toString()); } private static void printError(HttpServletResponse response, String message) { try { PrintWriter out = response.getWriter(); StringBuffer buffer = new StringBuffer(); buffer.append("<html><body>"); buffer.append(message); buffer.append("</body></html>"); out.println(buffer); } catch(Exception ignore) { } }
CHAPTER 9 WEB ACCESS TO METADATA, PART 2
/** * Get Column Privileges: retrieves a description of the access * rights for each table available in a catalog. Note that a * table privilege applies to one or more columnPrivileges in the table. * It would be wrong to assume that this privilege applies to * all columnPrivileges (this may be true for some systems but is not * true for all.) The result is returned as a ResultSet object. * * In JDBC, Each privilege description has the following columnPrivileges: * * TABLE_CAT String => table catalog (may be null) * TABLE_SCHEM String => table schema (may be null) * TABLE_NAME String => table name * COLUMN_NAME String => column name * GRANTOR => grantor of access (may be null) * GRANTEE String => grantee of access * PRIVILEGE String => name of access (SELECT, INSERT, * UPDATE, REFERENCES, ...) * IS_GRANTABLE String => "YES" if grantee is permitted to grant * to others; "NO" if not; null if unknown * * * @param conn the Connection object * @param catalog a catalog. * @param schema a schema. * @param table a table name * @param columnNamePattern column name pattern; * @return a ResultSet object * @exception Failed to get the Get Column Privileges. */ public static ResultSet getColumnPrivileges(Connection conn, String catalog, String schema, String table, String columnNamePattern) throws Exception { if ((table == null) || (table.length() == 0)) { return null; } DatabaseMetaData meta = conn.getMetaData(); if (meta == null) { return null; }
Copyright © OnBarcode.com . All rights reserved.