Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 6, 2016
0 parents commit 4affab8
Show file tree
Hide file tree
Showing 268 changed files with 20,453 additions and 0 deletions.
Binary file added 2658.pdf
Binary file not shown.
Binary file added 2659.pdf
Binary file not shown.
Binary file added 9781590596371.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2006 Mahmoud Parsian

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*JDBC Metadata, MySQL, and Oracle Recipes*](http://www.apress.com/9781590596371) by Mahmoud Parsian (Apress, 2006).

![Cover image](9781590596371.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
14 changes: 14 additions & 0 deletions contributing.md
@@ -0,0 +1,14 @@
# Contributing to Apress Source Code

Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.

## How to Contribute

1. Make sure you have a GitHub account.
2. Fork the repository for the relevant book.
3. Create a new branch on which to make your change, e.g.
`git checkout -b my_code_contribution`
4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
5. Submit a pull request.

Thank you for your contribution!
Binary file not shown.
@@ -0,0 +1,28 @@
import java.util.*;
import java.io.*;
import java.sql.*;
import jcb.util.DatabaseUtil;
import jcb.meta.DatabaseMetaDataTool;
import jcb.db.VeryBasicConnectionManager;

public class TestDatabaseMetaDataTool_DatabaseInformation {
public static void main(String[] args) {
String dbVendor = args[0]; // { "mysql", "oracle" }
Connection conn = null;
try {
conn = VeryBasicConnectionManager.getConnection(dbVendor);
System.out.println("-------- getDatabaseformation -------------");
System.out.println("conn="+conn);
String dbInfo = DatabaseMetaDataTool.getDatabaseInformation(conn);
System.out.println(dbInfo);
System.out.println("------------------------------------");
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
finally {
DatabaseUtil.close(conn);
}
}
}
Binary file not shown.
89 changes: 89 additions & 0 deletions sourceMetadata/Chapter02/GetColumnNamesFromResultSet_MySQL.java
@@ -0,0 +1,89 @@
import java.util.*;
import java.io.*;
import java.sql.*;

import jcb.db.*;
import jcb.meta.*;
import jcb.util.DatabaseUtil;

public class GetColumnNamesFromResultSet_MySQL {

public static Connection getConnection() throws Exception {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost/octopus";
String username = "root";
String password = "root";

Class.forName(driver); // load MySQL driver
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}

public static String getColumnNames(ResultSet rs)
throws SQLException {
if (rs == null) {
return null;
}

// get result set meta data
ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
StringBuffer columnNames = new StringBuffer("<columnNames>");

// get the column names; column indexes start from 1
for (int i=1; i<numberOfColumns+1; i++) {
String columnName = rsMetaData.getColumnName(i);
// Get the name of the column's table name
String tableName = rsMetaData.getTableName(i);
columnNames.append("<column name=\""+columnName+"\" table=\""+tableName+"\"/>");
}
columnNames.append("</columnNames>");
return columnNames.toString();
}

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
System.out.println("------GetColumnNamesFromResultSet_MySQL begin---------");

conn = getConnection();
System.out.println("conn="+conn);
System.out.println("---------------");

//
// prepare query
//
String query = "select id, name, age from employees";

//
// create a statement
//
stmt = conn.createStatement();


//
// execute query and return result as a ResultSet
//
rs = stmt.executeQuery(query);

//
// get the column names from the ResultSet
//
String columnNames = getColumnNames(rs);
System.out.println(columnNames);
System.out.println("------GetColumnNamesFromResultSet_MySQL end---------");
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
finally {
// release database resources
DatabaseUtil.close(rs);
DatabaseUtil.close(stmt);
DatabaseUtil.close(conn);
}
}
}
Binary file not shown.
89 changes: 89 additions & 0 deletions sourceMetadata/Chapter02/GetColumnNamesFromResultSet_Oracle.java
@@ -0,0 +1,89 @@
import java.util.*;
import java.io.*;
import java.sql.*;

import jcb.db.*;
import jcb.meta.*;
import jcb.util.DatabaseUtil;

public class GetColumnNamesFromResultSet_Oracle {

public static Connection getConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:caspian";
String username = "mp";
String password = "mp2";

Class.forName(driver); // load Oracle driver
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}

public static String getColumnNames(ResultSet rs)
throws SQLException {
if (rs == null) {
return null;
}

// get result set meta data
ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
StringBuffer columnNames = new StringBuffer("<columnNames>");

// get the column names; column indexes start from 1
for (int i=1; i<numberOfColumns+1; i++) {
String columnName = rsMetaData.getColumnName(i);
// Get the name of the column's table name
String tableName = rsMetaData.getTableName(i);
columnNames.append("<column name=\""+columnName+"\" table=\""+tableName+"\"/>");
}
columnNames.append("</columnNames>");
return columnNames.toString();
}

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
System.out.println("------GetColumnNamesFromResultSet_Oracle begin---------");

conn = getConnection();
System.out.println("conn="+conn);
System.out.println("---------------");

//
// prepare query
//
String query = "select id, name, age from employees";

//
// create a statement
//
stmt = conn.createStatement();


//
// execute query and return result as a ResultSet
//
rs = stmt.executeQuery(query);

//
// get the column names from the ResultSet
//
String columnNames = getColumnNames(rs);
System.out.println(columnNames);
System.out.println("------GetColumnNamesFromResultSet_Oracle end---------");
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
finally {
// release database resources
DatabaseUtil.close(rs);
DatabaseUtil.close(stmt);
DatabaseUtil.close(conn);
}
}
}
Binary file not shown.
48 changes: 48 additions & 0 deletions sourceMetadata/Chapter02/GetColumnPrivileges_Oracle.java
@@ -0,0 +1,48 @@
import java.util.*;
import java.io.*;
import java.sql.*;

import jcb.db.*;
import jcb.meta.*;
import jcb.util.DatabaseUtil;

public class GetColumnPrivileges_Oracle {

public static Connection getConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:caspian";
String username = "system";
String password = "password";
Class.forName(driver); // load Oracle driver
return DriverManager.getConnection(url, username, password);
}

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = getConnection();
System.out.println("conn="+conn);
System.out.println("---------------");

String columnPrivileges = DatabaseMetaDataTool.getColumnPrivileges
(conn, // connection
conn.getCatalog(), // catalog
"SYSTEM", // schema
"HELP",
"%");
System.out.println("---- Table's Columns Privileges ----");
System.out.println(columnPrivileges);
System.out.println("------------------------------------");
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
finally {
// release database resources
DatabaseUtil.close(conn);
}
}
}
Binary file not shown.
@@ -0,0 +1,28 @@
import java.util.*;
import java.io.*;
import java.sql.*;
import jcb.util.DatabaseUtil;
import jcb.meta.DatabaseMetaDataTool;
import jcb.db.VeryBasicConnectionManager;

public class TestDatabaseMetaDataTool_DatabaseInformation {
public static void main(String[] args) {
String dbVendor = args[0]; // { "mysql", "oracle" }
Connection conn = null;
try {
conn = VeryBasicConnectionManager.getConnection(dbVendor);
System.out.println("--- getDatabaseInformation ---");
System.out.println("conn="+conn);
String dbInfo = DatabaseMetaDataTool.getDatabaseInformation(conn);
System.out.println(dbInfo);
System.out.println("------------------------------------");
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
finally {
DatabaseUtil.close(conn);
}
}
}
Binary file not shown.

0 comments on commit 4affab8

Please sign in to comment.