H2 Database上でSchemaCrawlerを使用するユーザー定義関数のまとめ
スキーマを列挙する関数を作成する
テーブルを列挙する関数を作成する
テーブルのカラムを列挙する関数を作成する
データベースの情報を取得する関数を作成する
データベースのプロパティ情報を取得する関数を作成する
SchemaCrawlerの情報を取得する関数を作成する
ラベル H2Database_SchemaCrawler の投稿を表示しています。 すべての投稿を表示
ラベル H2Database_SchemaCrawler の投稿を表示しています。 すべての投稿を表示
2011年6月19日日曜日
2011年4月4日月曜日
H2 DatabaseとSchemaCrawlerでテーブルのカラムを列挙する関数を作成する
H2 DatabaseとSchemaCrawlerでテーブルのカラムを列挙する関数を作成するには、以下のスクリプトを実行します。
実行例
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
create alias if not exists sc_get_columns as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import schemacrawler.schema.*;
import schemacrawler.schemacrawler.*;
import schemacrawler.utility.*;
@CODE
ResultSet sc_get_columns(String jdbcDriver, String url,
String user, String password, String schemaName,
String tableName)
throws Exception
{
if( jdbcDriver == null ){
throw new Exception("jdbcDriver is not specified.");
}
if( url == null ){
throw new Exception("url is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( password == null ){
throw new Exception("password is not specified.");
}
if( schemaName == null ){
throw new Exception("schemaName is not specified.");
}
if( tableName == null ){
throw new Exception("tableName is not specified.");
}
Class.forName(jdbcDriver);
Connection conn = null;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("POS", Types.NUMERIC, 4, 0);
rs.addColumn("NAME", Types.VARCHAR, 4096, 0);
rs.addColumn("TYPENAME", Types.VARCHAR, 4096, 0);
rs.addColumn("DECIMAL_DIGITS", Types.NUMERIC, 4, 0);
rs.addColumn("SIZE", Types.NUMERIC, 10, 0);
rs.addColumn("WIDTH", Types.VARCHAR, 4096, 0);
rs.addColumn("NULLABLE", Types.BOOLEAN, 1, 0);
try
{
conn = DriverManager.getConnection(url, user, password);
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
options.setSchemaInfoLevel(SchemaInfoLevel.maximum());
Database db = SchemaCrawlerUtility.getDatabase(conn, options);
Schema schema = db.getSchema(schemaName);
if( schema != null ){
Table table = schema.getTable(tableName);
if( table != null ){
Column columns[] = table.getColumns();
for(int li=0;li<columns.length;li++){
rs.addRow(columns[li].getOrdinalPosition(),
columns[li].getName(),
columns[li].getType().getTypeName(),
columns[li].getDecimalDigits(),
columns[li].getSize(),
columns[li].getWidth(),
columns[li].isNullable());
}
}
}
}
finally
{
if( conn != null )conn.close();
}
return rs;
}
$$
実行例
select * from
sc_get_columns('org.postgresql.Driver',
'jdbc:postgresql://localhost:5432/postgres',
'postgres', 'postgres', 'public', 'test1');
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
2011年4月2日土曜日
H2 DatabaseとSchemaCrawlerでテーブルを列挙する関数を作成する
H2 DatabaseとSchemaCrawlerでテーブルを列挙する関数を作成するには、以下のスクリプトを実行します。
実行例
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
create alias if not exists sc_get_tables as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import schemacrawler.schema.*;
import schemacrawler.schemacrawler.*;
import schemacrawler.utility.*;
@CODE
ResultSet sc_get_tables(String jdbcDriver, String url,
String user, String password, String schemaName)
throws Exception
{
if( jdbcDriver == null ){
throw new Exception("jdbcDriver is not specified.");
}
if( url == null ){
throw new Exception("url is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( password == null ){
throw new Exception("password is not specified.");
}
if( schemaName == null ){
throw new Exception("schemaName is not specified.");
}
Class.forName(jdbcDriver);
Connection conn = null;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 4096, 0);
rs.addColumn("FULLNAME", Types.VARCHAR, 4096, 0);
rs.addColumn("REMARKS", Types.VARCHAR, 4096, 0);
try
{
conn = DriverManager.getConnection(url, user, password);
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
Database db = SchemaCrawlerUtility.getDatabase(conn, options);
Schema schema = db.getSchema(schemaName);
if( schema != null ){
Table tables[] = schema.getTables();
for(int li=0;li<tables.length;li++){
rs.addRow(tables[li].getName(),
tables[li].getFullName(),
tables[li].getRemarks());
}
}
}
finally
{
if( conn != null )conn.close();
}
return rs;
}
$$
実行例
select * from
sc_get_tables('org.postgresql.Driver',
'jdbc:postgresql://localhost:5432/postgres',
'postgres', 'postgres', 'public');
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
2011年3月22日火曜日
H2 DatabaseとSchemaCrawlerでスキーマを列挙する関数を作成する
H2 DatabaseとSchemaCrawlerでスキーマを列挙する関数を作成するには、以下のスクリプトを実行します。
実行例
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
create alias if not exists sc_get_schemas as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import schemacrawler.schema.*;
import schemacrawler.schemacrawler.*;
import schemacrawler.utility.*;
@CODE
ResultSet sc_get_schemas(String jdbcDriver, String url,
String user, String password)
throws Exception
{
if( jdbcDriver == null ){
throw new Exception("jdbcDriver is not specified.");
}
if( url == null ){
throw new Exception("url is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( password == null ){
throw new Exception("password is not specified.");
}
Class.forName(jdbcDriver);
Connection conn = null;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("CATALOG", Types.VARCHAR, 4096, 0);
rs.addColumn("SCHEMA", Types.VARCHAR, 4096, 0);
try
{
conn = DriverManager.getConnection(url, user, password);
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
Database db = SchemaCrawlerUtility.getDatabase(conn, options);
Schema schemas[] = db.getSchemas();
for(int li=0;li<schemas.length;li++){
rs.addRow(schemas[li].getCatalogName(),
schemas[li].getSchemaName());
}
}
finally
{
if( conn != null )conn.close();
}
return rs;
}
$$
実行例
select * from
sc_get_schemas('org.postgresql.Driver',
'jdbc:postgresql://localhost:5432/postgres',
'postgres', 'postgres');
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
2011年3月12日土曜日
H2 DatabaseでSchemaCrawlerの情報を取得する関数を作成する
H2 DatabaseでSchemaCrawlerの情報を取得する関数を作成するには、以下のスクリプトを実行します。
実行例
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
create alias if not exists sc_get_scinfo as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import schemacrawler.schema.*;
import schemacrawler.schemacrawler.*;
import schemacrawler.utility.*;
@CODE
ResultSet sc_get_scinfo(String jdbcDriver, String url,
String user, String password)
throws Exception
{
if( jdbcDriver == null ){
throw new Exception("jdbcDriver is not specified.");
}
if( url == null ){
throw new Exception("url is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( password == null ){
throw new Exception("password is not specified.");
}
Class.forName(jdbcDriver);
Connection conn = null;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 4096, 0);
rs.addColumn("VALUE", Types.VARCHAR, 4096, 0);
try
{
conn = DriverManager.getConnection(url, user, password);
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
Database db = SchemaCrawlerUtility.getDatabase(conn, options);
SchemaCrawlerInfo sci = db.getSchemaCrawlerInfo();
rs.addRow("About", sci.getSchemaCrawlerAbout());
rs.addRow("ProductName", sci.getSchemaCrawlerProductName());
rs.addRow("Version", sci.getSchemaCrawlerVersion());
}
finally
{
if( conn != null )conn.close();
}
return rs;
}
$$
実行例
select * from
sc_get_scinfo('org.postgresql.Driver',
'jdbc:postgresql://localhost:5432/postgres',
'postgres', 'postgres');
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
2011年3月2日水曜日
H2 DatabaseとSchemaCrawlerでデータベースのプロパティ情報を取得する関数を作成する
H2 DatabaseとSchemaCrawlerでデータベースのプロパティ情報を取得する関数を作成するには、以下のスクリプトを実行します。
実行例
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
create alias if not exists sc_get_dbprops as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import schemacrawler.schema.*;
import schemacrawler.schemacrawler.*;
import schemacrawler.utility.*;
@CODE
ResultSet sc_get_dbprops(String jdbcDriver, String url,
String user, String password)
throws Exception
{
if( jdbcDriver == null ){
throw new Exception("jdbcDriver is not specified.");
}
if( url == null ){
throw new Exception("url is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( password == null ){
throw new Exception("password is not specified.");
}
Class.forName(jdbcDriver);
Connection conn = null;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 4096, 0);
rs.addColumn("VALUE", Types.VARCHAR, 4096, 0);
rs.addColumn("DESCRIPTION", Types.VARCHAR, 4096, 0);
try
{
conn = DriverManager.getConnection(url, user, password);
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
options.setSchemaInfoLevel(SchemaInfoLevel.maximum());
Database db = SchemaCrawlerUtility.getDatabase(conn, options);
DatabaseInfo dbi = db.getDatabaseInfo();
DatabaseProperty props[] = dbi.getProperties();
for(int pl=0;pl<props.length;pl++){
rs.addRow(props[pl].getName(),
props[pl].getValue(), props[pl].getDescription());
}
}
finally
{
if( conn != null )conn.close();
}
return rs;
}
$$
実行例
select * from
sc_get_dbprops('org.postgresql.Driver',
'jdbc:postgresql://localhost:5432/postgres',
'postgres', 'postgres');
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
2011年2月20日日曜日
H2 DatabaseとSchemaCrawlerでデータベースの情報を取得する関数を作成する
H2 DatabaseとSchemaCrawlerでデータベースの情報を取得する関数を作成するには、以下のスクリプトを実行します。
実行例
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
create alias if not exists sc_get_dbinfo as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import schemacrawler.schema.*;
import schemacrawler.schemacrawler.*;
import schemacrawler.utility.*;
@CODE
ResultSet sc_get_dbinfo(String jdbcDriver, String url,
String user, String password)
throws Exception
{
if( jdbcDriver == null ){
throw new Exception("jdbcDriver is not specified.");
}
if( url == null ){
throw new Exception("url is not specified.");
}
if( user == null ){
throw new Exception("user is not specified.");
}
if( password == null ){
throw new Exception("password is not specified.");
}
Class.forName(jdbcDriver);
Connection conn = null;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 4096, 0);
rs.addColumn("VALUE", Types.VARCHAR, 4096, 0);
try
{
conn = DriverManager.getConnection(url, user, password);
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
Database db = SchemaCrawlerUtility.getDatabase(conn, options);
DatabaseInfo dbi = db.getDatabaseInfo();
rs.addRow("ProductName", dbi.getProductName());
rs.addRow("ProductVersion", dbi.getProductVersion());
rs.addRow("UserName", dbi.getUserName());
}
finally
{
if( conn != null )conn.close();
}
return rs;
}
$$
実行例
select * from
sc_get_dbinfo('org.postgresql.Driver',
'jdbc:postgresql://localhost:5432/postgres',
'postgres', 'postgres');
※以下のjarをCLASSPATH環境変数に追加
schemacrawler-8.5.1.jar, schemacrawler-postgresql-8.5.1.jar
○動作環境
JDK6 Update23, H2 Database 1.2.149 (2011-01-07), SchemaCrawler 8.5.1
○関連情報
・SchemaCrawlerのウェブサイト
http://schemacrawler.sourceforge.net/
・H2 Databaseに関する他の記事はこちらを参照してください。
登録:
投稿 (Atom)