org.jsqltool.conn
Class DbConnectionUtil

java.lang.Object
  |
  +--org.jsqltool.conn.DbConnectionUtil

public class DbConnectionUtil
extends java.lang.Object

Title: JSqlTool Project

Description: Utility Class used to connect to the database and fetch data.

Copyright: Copyright (C) 2006 Mauro Carniel

This file is part of JSqlTool project. This library is free software; you can redistribute it and/or modify it under the terms of the (LGPL) Lesser General Public License as published by the Free Software Foundation; GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The author may be contacted at: maurocarniel@tin.it


Constructor Summary
DbConnectionUtil(javax.swing.JFrame parent, DbConnection c)
          Create a database connection.
 
Method Summary
 java.lang.String convertDateToString(java.util.Date date)
           
 int executeStmt(java.lang.String stmt, java.util.Vector parameters)
          Execute a SQL Script.
 java.sql.Connection getConn()
           
 javax.swing.table.TableModel getCrossReference(java.lang.String tableName)
           
 DbConnection getDbConnection()
           
 int getLastQueryIndex(java.lang.String query, java.util.Vector parameters, int maxRows)
           
 java.util.Hashtable getPK(java.lang.String tableName)
           
 javax.swing.table.TableModel getQuery(java.lang.String query, java.util.Vector parameters)
           
 javax.swing.table.TableModel getQuery(java.lang.String query, java.util.Vector parameters, int startPos, int maxRows)
           
 java.util.List getSchemas()
           
 javax.swing.table.TableModel getTableColumns(java.lang.String tableName)
           
 javax.swing.table.TableModel getTableIndexes(java.lang.String tableName)
           
 java.util.List getTables(java.lang.String schema, java.lang.String tableType)
           
 void saveProfile(boolean isEdit)
           
 void writeBlob(byte[] bytes, java.sql.PreparedStatement stmt)
          Store a byte[] a BLOB field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbConnectionUtil

public DbConnectionUtil(javax.swing.JFrame parent,
                        DbConnection c)
Create a database connection.

Parameters:
c - databse connection descriptor
Method Detail

getConn

public java.sql.Connection getConn()
Returns:
database connection

saveProfile

public void saveProfile(boolean isEdit)

getTables

public java.util.List getTables(java.lang.String schema,
                                java.lang.String tableType)
Returns:
tables list, filtered by schema

getSchemas

public java.util.List getSchemas()
Returns:
catalogs list

getQuery

public javax.swing.table.TableModel getQuery(java.lang.String query,
                                             java.util.Vector parameters)
Parameters:
query - query to execute
Returns:
table model which contains a block of records

getTableColumns

public javax.swing.table.TableModel getTableColumns(java.lang.String tableName)
Parameters:
tableName - table name
Returns:
table columns

getPK

public java.util.Hashtable getPK(java.lang.String tableName)
Parameters:
tableName - table name used to retrieve its pk
Returns:
collection of links (pk field name,table model column index)

getTableIndexes

public javax.swing.table.TableModel getTableIndexes(java.lang.String tableName)
Parameters:
tableName - table name used to retrieve its indexes
Returns:
table indexes

getCrossReference

public javax.swing.table.TableModel getCrossReference(java.lang.String tableName)
Parameters:
tableName - table name used to retrieve its fk
Returns:
table fks

getQuery

public javax.swing.table.TableModel getQuery(java.lang.String query,
                                             java.util.Vector parameters,
                                             int startPos,
                                             int maxRows)
Parameters:
query - query to execute
startPos - first record to read
maxRows - max number of records to read
Returns:
table model which contains the records

getLastQueryIndex

public int getLastQueryIndex(java.lang.String query,
                             java.util.Vector parameters,
                             int maxRows)
Parameters:
query - query to execute
maxRows - max number of records to read
Returns:
result set index of the first record of the last block

executeStmt

public int executeStmt(java.lang.String stmt,
                       java.util.Vector parameters)
Execute a SQL Script.

Parameters:
stmt - SQL statement to execute
Returns:
number of rows updated

getDbConnection

public DbConnection getDbConnection()

convertDateToString

public java.lang.String convertDateToString(java.util.Date date)

writeBlob

public final void writeBlob(byte[] bytes,
                            java.sql.PreparedStatement stmt)
                     throws java.lang.Exception
Store a byte[] a BLOB field.

Parameters:
bytes - byte[] to store
stmt - statement whose first element is a BLOB field
java.lang.Exception